New answers tagged

2

Method 1 You can use activate_plugin() and deactivate_plugins() to activate/deactivate plugins programmatically. If you want to control the time at which those actions happen, then you can use wp_schedule_event() too. Method 2 I know you asked about PHP, but if you have WP-CLI installed on your server, you can also write a script that uses wp plugin ...


1

Up-voting Andy's answer, you should be comparing integers to get this working. strtotime() can turn any string to the time integer, which will be compared later to tell the difference and how many seconds passed until now ( time() ). Something like follows: $expired = ( ( time() - strtotime(get_the_date('Y-m-d H:i:s')) ) / DAY_IN_SECONDS ) >= 5; if ( $...


1

If you have deactivated the first one you should be able to use the new one without any hassle. When the plugin deactivated, WP core don't call any of it function or doesn't use any thing else from it. But if you activated both of them then it can cause function re-declaration etc.


2

You're comparing strings. For dates this will only ever work out if you use a yyyymmdd format or similar.


0

<?php global $wpdb; // QUERY HERE TO COUNT TOTAL RECORDS FOR PAGINATION $total = $wpdb->get_var("SELECT COUNT(*) FROM (SELECT * FROM muslim LIMIT 0,431) AS a"); $post_per_page = 10; $page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1; $offset = ( $page * $post_per_page ) - $post_per_page; // QUERY HERE TO GET OUR RESULTS $results = $...


1

Forget about connecting to your database while WordPress is ready and connected by default. Go after wpdb class for DB-specific tasks. First, call the global $wpdb variable which is the db class, and then use few methods to query your specific custom table. Not sure about the table structure? describe it first: global $wpdb; $table = $wpdb->prefix . "...


0

If no role is checked when you submit, the $_POST['cat'] will not be set. That will trigger the "invalid argument supplied for foreach" error. In the beginning of your if ( isset($_POST['saveme']) ) structure, I'd put: if ( !isset($_POST['cat']) ) { // code to update db value to 0 }


0

If your web host won't let you have access to cron jobs, you can try one of the free external cron job services (I used one of these but now forgot which one) https://www.google.com/search?q=web+cron+free ... if your script has a public URL. I added a hashed code to my script to make sure no one could just call the script directly w/o the key.


0

I recommend using the ManageWP service as they allow for automatic backups of files and database which can also be easily configured to automatically send to an external source, drive, etc. In addition, they offer uptime monitors for your websites and you can run security scans. Just a great tool all around. Here are some more details regarding the backups ...


0

your variable $roles , either contains no value or is not an array, foreach only process an array/object.


0

You need to create separate tables for store sticky notes and save user sticky notes to that tables , in this way you can manage multiple sticky notes of user. i think this idea will help you.


1

I am not confident without downloading Estonian copy of WP source, but from look at GlotPress it seems that locale code for it is simply et, not et_EE.


0

This is not a wordpress-related question but a HTML or JS related one. The button probably has a target="_blank" attribute which you need to get rid of. The case is not clear.


0

I usualy use : sudo chown -R _www:_www /path/to/wordpress/


0

If I've understood correctly, you just want older images upgraded to be like newer images? Back up your data first, but if I have understood then just remaking your image sets with a plugin like Regenerate Thumbnails should do the trick. Test this out on a development copy of your site though!


2

These are almost certainly custom post types. In the definition of the custom post type, it is possible to define a menu_icon which can be a file or an icon from the iconfont. It is this menu_icon that is showing up in your admin menu. I also notice "Programs Categories" in your menu, this looks like a custom options page - which will have also been ...


0

You can use the _core_updated_successfully action hook to run your plugin code after the WordPress core upgrade. The hook passes the current WordPress Version as parameter. add_action( '_core_updated_successfully','your_function'); function your_function(){ //code to be executed after WordPress Core Update }


0

Responsiveness is probably one of the most important things about any site. Finding a way to make your table responsive is then pretty key. If you want to go the plugin route, it is best to look for a table plugin that offers that responsiveness. Also, plugging HTML into your theme may have some unintended design consequences depending on your theme. So ...


0

You should pick whichever route is easiest to implement now and maintain in the future. Ideally the solution you pick should be repeatable for other post/pages.


0

When I realized that PHP is an acronym for "PHP Hypertext Preprocessor" -- emphasis on "preprocessor" -- I finally understood that I can't mix PHP and HTML and expect any kind of interactivity with the user. When a web page is served, the PHP creates the HTML and then the HTML is displayed by the browser. If the user does something the PHP must respond to, ...


9

There is no definite answer as each plugin, whether available in a repo or not, should be handled on its own merit. Also, who says that that plugin caused your site to get hacked, it might have being a loophole in another plugin or even your theme. Just in general, one should avoid using plugins and themes that are not actively being maintained as it does ...


0

I did this for a mock movie DB in school. You can have each product their own unique ID, and upon clicking it, have it open in a generic page based on the ID, and find everything identifying with it matching that ID. So if a customer clicks a product, such as shampoo, with an ID of 3076, then it will pull up anything with 3076 associated. Just pass this ...


-2

<?php global $wpdb; $table="test_table"; $store_arr["name"]="test"; $store_arr["email"]="test@gmail.com"; $wpdb->insert( $table, $store_arr); ?>


1

Setting theme dynamically is certainly possible, but not too convenient since it's hardly "normal" mode of operation. In my experience this works best if you stay away from higher level template/stylesheet hooks and instead filter underlying options. In that way you can trick WP into thinking that configured theme is different from what it is and use it. ...


0

Why don't you create a shortcode for this , it's much easier, standard and flexible.


0

Short answer: most probably there is. I would recommend you use a child theme to achieve this. You can then copy any of the parent theme's templates into your child theme and alter them as you like. In your case it's probably something like "single-portfolio.php" inside the templates folder of the theme. A good starting point for working with child themes ...


0

In this code I am changing the columns of my edit.php page, I am basically keeping only the checkbox, author and date I am adding acf fields from the posts to the edit.php page but you can add other meta there. /* ------------------------------------------------------------------------------- Custom Columns -----------------------------------------------...


1

See documentation here but don't miss the note 2 and the following points : AJAX on the front-end is more complicated, ajaxurl is not defined so you have to call it with wp_localize_script(). you have to use wp_ajax_nopriv_{action} for non logged in users there could be security issue !!! About the third point : Be careful because you give access to ...


0

//Using this code you can activate your plugin from the functions.php function activate_plugin_via_php() { $active_plugins = get_option( 'active_plugins' ); array_push($active_plugins, 'unyson/unyson.php'); /* Here just replace unyson plugin directory and plugin file*/ update_option( 'active_plugins', $active_plugins ); } ...


0

You should never use relative urls in wordpress except for css files. If "pretty permalink" something that works on one page might break on another. All urls should be absolute. The most you can get with usually is being relative to the protocol, but almost never anything more then that.


1

Move the return $title; one line lower. You are not returning anything for administration.


-1

<div class="fill" style="background-image:url("img/image01.png");"></div> Your double quotes within double quotes will stop it from working, you need: <div class="fill" style="background-image:url('img/image01.png');"></div>


0

I actually solved this... here's what you need to do if anyone needs to do something similar: SO, you can't really query a site, but you can query pages on sites... so what I did was make a new page on the site where everything looked good, embed the shortcode, query that page and the content only on the other site. You NEED to have the site switch to that ...


0

You can use this code and it will really help you a lot <?php require( '../wp-load.php' ); get_header(newtheme); echo 'new content outside WordPress'; get_footer(); ?>


1

That's WordPress API and the proper tool to use for this is register_activation_hook which fires right after your plugin activation, or after_setup_theme if you were doing this work for a theme. Here's an example use, the code should be placed in the main plugin loader file, or if in a sub-directory then provide a path to __FILE__ property from the main ...


1

That's not a good practice trying to connect the DB by your own methods while WP does it for you initially. The problem with this is that I have to declare these variables ($db_host, $db_user, $db_pass, $db_name) inside the plugin source code. All these properties are defined in wp-config.php file, located in the root area. If you were to get ...


0

What's the risk? On a poorly configured shared host, every customer's PHP will execute as the same user (let's say apache for discussion). This setup is surprisingly common. If you're on such a host and use WordPress to install the plugin using direct file access, all of your plugin files will belong to apache. A legitimate user on the same server would ...


1

Why not study about how $wpdb works. Visit https://codex.wordpress.org/Class_Reference/wpdb Here is a example of how to insert data to database using $wpdb <?php global $wpdb; $wpdb->insert( 'table_name_here', array( 'column1' => 'value1', 'column2' => 123 ), array( '%s', '%d' ) ...


-1

The markup of your button is <input disabled="" class="woocommerce-Button button" value="Reset Password" type="submit"> it shouldn't be disabled, removing the disabled attr doesn't seem to fix the problem, but I think that this button is "Decoration", and it is not associated with any ajax request, the theme default functionality for reset password ...


0

You can get current user ID easily using get_current_user_id(). $usersid = get_current_user_id(); $activity = $_POST['activity']; $reason = $_POST['reason']; $explanation = $_POST['explanation']; For your function f2user() you can change your code to this: $current_user = wp_get_current_user(); return $current_user->ID; According to ...


0

You may not have the xdebug PHP extension enabled. When I run the tests without xdebug enabled on PHPUnit 4.8.26, I get this message: Warning: The Xdebug extension is not loaded No code coverage will be generated. It looks like VVV comes with xdebug though, so it is probably enabled by default. But perhaps you disabled it somehow? To check ...


0

You could use the WP User Avatar plugin for this.


1

The only way WordPress is going to know what the previous option was, is if you save it before you change it - since you're replacing the built-in option, it has no way of knowing how to get back to that. So, you could add a custom 'backup' option that you restore on deactivation. Something like this when your option is first set: function set_hp(){ ...


0

As of WordPress 3.0.0 this action is available at the top of the new user form: user_new_form_tag As of WordPress 3.7.0 this action is called at the end of the form (right before submit button): user_new_form You will however need to intercept when clicking submit to save any specific user information to the user's meta


0

This can be done as concisely as follows (in your theme functions.php or a plugin): function wpse_231970_lockdown() { if ( ! is_user_logged_in() ) { global $wp; /** * Redirect to login page with redirect back to current request. */ wp_redirect( wp_login_url( $wp->request ) ); exit; } } ...


0

Why you not get ID from permalink? That' s possible. You can check if post ID not exists to check by permalink parsing URL or direcly check GET if is permalink off. WP have a bunch of ways to get ID. You also can use this function: https://codex.wordpress.org/Function_Reference/url_to_postid


1

I don't know why your $_POST data disappears. However, consider using the admin_post/admin_post_nopriv hook to process the form data using a function on the back end. That's what the function was made for. At the end of the function, you can then redirect to the account-pending page using this wp_redirect(home_url('/account-pending')) .


5

If all that you want to test is that the translation files exist, then this is probably the simplest approach, since you'll probably already be using PHPUnit to run unit/integration tests on the plugin code. However, just checking whether the files exist doesn't tell you much. It doesn't tell you whether those languages are actually fully translated, or ...


0

You can basically deactivate whole plugin only based on the information you have at wordpress "boot" time, which is basically the URL and cookies. Any check more complex then that will probably have to wait until boot is completed to be able to be executed, at which time the plugin is already loaded and it is too late to "deactivate" it.


4

Have a look at the Network Admin Settings screen (in my installation, it's at example.com/wp-admin/network/settings.php). Tucked away down near the bottom is this: Menu Settings Enable administration menus [] Plugins Checking that box should allow your users to see the Plugins menu in their sites' back end. (I don't think it'll allow them to ...



Top 50 recent answers are included