How to automate wordpress plugin activate and deactivate by php logic?

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 … Read more

WordPress security issue to output data from user input from theme option form

Security issues arise when you write code that open up possibilities for outsiders to access your database or otherwise compromise your installation. The above code just reads options and content from the database and translates this into static html that will be send to the browser of the page’s visitor. There’s no code (like a … Read more

How to delete an user including data from custom database tables

Hello guys! i resolved this issue by using same hook add_action( ‘delete_user’, ‘my_delete_user’ ); here is my code <?php function my_delete_user( $user_id ) { global $wpdb; $user_obj = get_userdata( $user_id ); $id_user = $user_obj->ID; $idsss = $user_obj->user_id; /*Delete Data from friend table*/ $query_friend= $wpdb->query(“DELETE FROM `wp_user_friends` where `friend_id` = “.$user_obj->ID.””); /*delete data from group*/ $delete_group_table … Read more

Can I individually style items in the backend widget list?

Just as @MarkKaplun mentioned in a comment, it’s possible with CSS. Also with Javascript. CSS Approach Let’s look at the Calendar widget, as an example. The id for the widget, in the available widgets list, is of the form: widget-{integer}_calendar-__i__ and in the sidebar it’s: widget-{integer}_calendar-{integer} If we want to display the calendar dashicon before … Read more

How to untrash a post only if it was not a draft?

Just as @cybmeta mentioned, the info is stored in the post meta table. When we trash a post then the post meta key _wp_trash_meta_status is added with the value of the previous post status (publish, pending, draft, … ). Within the wp_trash_post() function, we have: add_post_meta($post_id,’_wp_trash_meta_status’, $post[‘post_status’]); add_post_meta($post_id,’_wp_trash_meta_time’, time()); We might therefore try: // Get … Read more