Hot answers tagged

18

You could do this using the WordPress uninstall.php support: <?php if( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) exit(); global $wpdb; $wpdb->query( "DROP TABLE IF EXISTS NestoNovo" ); delete_option("my_plugin_db_version"); ?> This uninstall.php file is called when your plugin is deleted.


11

Then you should see a link "Trash" on the top of pages/posts listing section. Click on that link which will take you the section where all the trashed pages/posts are listed. Select the pages/posts using the checkboxes against them. Select Restore from Bulk Actions dropdown, then hit the Apply button. Now go to pages/posts listing section and you should ...


6

before_delete_post is not called when a post is only trashed. While wp_delete_post() can trash posts (if the post is not trashed and its not being forcibly deleted): it does so by calling wp_trash_post() and exiting the function prior to the triggering the action before_delete_post. I've tested this, the following function will only 'die' when you ...


5

Try to use $wpdb->prefix insted of $wpdb in Delete query. Example: $wpdb->query( 'DELETE FROM '.$wpdb->prefix.'paypal WHERE id = "'.$myid.'"' );


4

Modify the coments of a deleted user It is possible to delete all comments of a registered user when he will be deleted (see my answer above), but in most cases it is a very stupid idea. If you do not use nested comments, than the only effect is, that some comments have no sense if they are replys on a deleted comment. If you use nested comments, than it ...


4

Since you only moved them to trash, you can easily restore them When you are on the posts or pages page in the admin area, click on the trash link at the top of the screen. Now you will see your posts or pages that you moved to trash, just hover over one of them and click on "restore" You can also use the checkboxes to select multiple at once, and from the ...


4

You can use 'the_title' filter (Codex link) add_filter( 'the_title', 'lose_four_chars'); function lose_four_chars($title) { if ( is_single()) { return substr($title, 4); } else { return $title; } }


4

By default, no, WordPress doesn't keep track of who changes post statuses (at least that I can see). you can hook into transition_post_status and log the user id. add_action( 'transition_post_status', 'wwm_transition_post_status', 10, 3 ); function wwm_transition_post_status( $new_status, $old_status, $post ) { if ( 'trash' == $new_status ) { ...


3

You can’t. WordPress tracks the recently active plugins for a while, but there is no history of deleted plugins. You could install a logger and track this information in a special place for the future.


3

When a user say user A is deleted, you're not cleaning up all traces of that user. Namely you need to go into each user following A and remove it from their user meta. This is why your function is showing blank users, because its being given stale information that's out of date, and refers to users that no longer exist You'll want to do this on the ...


3

Yes, by adding an action to the before_delete_post, delete_post, or deleted_post actions.


3

I would generally not recommend modifying files for Plugins that you do not control. Better would be to write your own site/custom Plugin, to control this hook: add_action('akismet_scheduled_delete', 'akismet_delete_old'); First, to stop the deletion altogether, simply call: remove_action('akismet_scheduled_delete', 'akismet_delete_old'); Then, you can ...


3

Add a parameter to your function, which will be passed the ID of the current post being deleted. add_action( 'delete_post', 'my_delete_function' ); function my_delete_function( $post_id /* <- ID of post being deleted */ ) { global $wpdb; $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}_votes WHERE post = %d", $post_id ) ); } ...


3

If you like, that users only can delete his own post, then it is important, that check for the ID of the user and the Author-ID to the post. The follow source example add a Trash button to the admin bar, that the users can easily delete his own post. The key is the function get_queried_object(). This object stored all values to the post on the front end and ...


3

Even if you find a way to reset the post and pretend it didn't happen, you shouldn't. WordPress uses a relational database structure. In short, a bunch of different tables in the database point to and rely on each other. The ID value of each row, such as the post ID for posts, is particularly important for linking different rows in different tables. For ...


2

I haven't tested so I'm providing you with two possibilities, Inside a loop, use the following: $post_id = get_the_ID(); Outside a loop, use the following: global $wp_query; $post_id = $wp_query->post->ID; Or: global $post; $post_id = $post->ID Or you can pass the post ID in a function, much like function my_function($post_id){ // code }


2

wp_delete_post() always triggers before_delete_post - the problem must be that you're hooking your function conditionally (i.e. not all the time). before_delete_post only gets triggered if you're actually deleting the post permanently, not just trashing it. If you need to listen for trashing too, use wp_trash_post.


2

Try: <?php if (current_user_can('edit_post', $post->ID)) echo "<a href='" . wp_nonce_url("/wp-admin/post.php?action=delete&amp;post=$id", 'delete-post_' . $post->ID) . "'>Delete post</a>" ?> You can decide when to empty the WordPress trash by adding this code to the wp-config.php file in your WordPress root directory. define('...


2

If WordPress is appending an incremental number to the end of the permalink, that means that the original page still exists in the database. Several options: Try looking in the Trash. Try re-adding an administrator account with the same username, email, etc. as the one that was deleted. Go into the DB, using PHPMyAdmin, and change the post_author of the ...


2

Using Types you CAN take over control of your existing custom fields. You don't need to delete them. Look under the Types--> Custom Field Control, select the fields and Bulk Edit to "Add to Types Control"


2

You have to search the wp_options database table for option_name's that contains widget. That search results in: Using the values of your backups, you'll then proceed to restore the option_value of the missing widgets. And also the value of the option of sidebars_widgets. Goes without saying that backing up before doing this modifications is essential.


2

You can add actions to the set_user_role hook: add_action( 'set_user_role', 'wpse98904_remove_demoted_user_posts', 10, 2 ); function wpse98904_remove_demoted_user_posts( $demoted_author_id, $role ) { if( 'subscriber' == $role ) { // In here you'd search for all the posts by the user $args = array( 'numberposts' => -...


2

The solution to this is to modify your restrict admin function to allow for certain circumstances. function restrict_admin() { // Bail if a user is trying to trash a post. if ( isset( $_GET[ 'action'] ) && 'trash' == $_GET[ 'action'] ) return; // Kill execution if not an administrator. if ( ! current_user_can( 'create_users'...


2

That's a lot of unattached images. If you have couple of hundred images then you can delete them manually from media library. 1. Click 'Screen Options' at the top right and set 'Show on screen' to 200. 2. Click 'Apply'. 3. Click the checkbox just under 'Bulk Actions' to check all images on the page. 4. Select 'Delete Permanently' in the 'Bulk Actions' ...


2

Have you seen this ? https://stackoverflow.com/a/28429009/3967385 Actually you can't fire JavaScript with php simply like that.


2

To use phpMyAdmin follow the steps below: Login to phpMyAdmin panel and select your WordPress database. Click on the SQL tab which will bring you to a page with a SQL query box. Once you see the SQL query box, like the image shown below, you can run your SQL query there. UPDATE wp_posts SET post_content = REPLACE (post_content, '<p style="text-align: ...


2

Do you have backups of your database? If not, ask your hosting provider if they have backup copies of your database from the time before the posts were deleted.


2

Following the line of code https://core.trac.wordpress.org/browser/tags/4.9/src/wp-includes/post.php#L2467 if ( ! $force_delete && ( 'post' === $post->post_type || 'page' === $post->post_type ) && 'trash' !== get_post_status( $postid ) && EMPTY_TRASH_DAYS ) { return wp_trash_post( $postid ); } the $force_delete just work ...


1

Download the theme-- actually download to your computer rather than use the built in updater/installer--, unzip it, find the footer file, and upload that to your site over FTP. After that, my advice would be to setup a development environment on your computer and don't edit the live site directly.


Only top voted, non community-wiki answers of a minimum length are eligible