Bạn đang xem: Uninstall
I have found this on the WordPress codex, but I don"t understand what to vị with it.. Shame
if ( !defined( "WP_UNINSTALL_PLUGIN" ) ) exit();$option_name = "plugin_option_name";delete_option( $option_name );// For site options in multisitedelete_site_option( $option_name ); //drop a custom db tableglobal $wpdb;$wpdb->query( "DROP TABLE IF EXISTS $wpdb->prefixmytable" );Can anyone help?
Thanks in advance
Would this be correct?
if ( !defined( "WP_UNINSTALL_PLUGIN" ) ) exit(); global $wpdb; $posts_table = $wpdb->posts; $query = " DELETE FROM wp_posts WHERE post_type = "messages" ";$wpdb->query($query);
Improve this question
edited Aug 8, năm trước at 11:15
asked Aug 8, 2014 at 8:04
42433 silver badges99 bronze badges
showroom a comment |
1 Answer 1
Sorted by: Reset to default
Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
The WP codex page http://codex.wordpress.org/Function_Reference/register_uninstall_hook has 2 important pieces of information, only 1 of which you menu in your question. You bởi need lớn make sure that you register the hook.
That aside, if you want to lớn remove all custom post data (regardless if it is upon uninstallation or as another person commented having a seperate button khổng lồ remove data as many plugins do) you need to be sure khổng lồ remove the postmeta records as well.
global $wpdb;$cptName = "messages";$tablePostMeta = $wpdb->prefix . "postmeta";$tablePosts = $wpdb->prefix . "posts";$postMetaDeleteQuery = "DELETE FROM $tablePostMeta". " WHERE post_id IN". " (SELECT id FROM $tablePosts WHERE post_type="$cptName"";$postDeleteQuery = "DELETE FROM $tablePosts WHERE post_type="$cptName"";$wpdb->query($postMetaDeleteQuery);$wpdb->query($postDeleteQuery);
Improve this answer
answered Aug 9, 2014 at 3:29
Adam ErstelleAdam Erstelle
2,41433 gold badges2121 silver badges3535 bronze badges
add a phản hồi |
Thanks for contributing an answer khổng lồ Stack Overflow!Please be sure lớn answer the question. Provide details & share your research!
But avoid …Asking for help, clarification, or responding khổng lồ other answers.Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
Sign up using Google
Sign up using Facebook
Sign up using e-mail and Password
Post as a guest
e-mail Required, but never shown
Post as a guest
thư điện tử
Required, but never shown
Post Your Answer Discard
Not the answer you're looking for? Browse other questions tagged or ask your own question.
The Overflow Blog Featured on Meta
Can I install/update WordPress plugins without providing FTP access?
wordpress mysql - delete all custom post type
Order by custom field (numeric) in WP_Query
Wordpress custom metabox, load on posts, pages, & all custom post types?
Mysql Left OUTER JOIN with Subquery (wordpress)
wordpress kiến thiết pattern name
Hot Network Questions more hot questions
Subscribe to lớn RSS
Question feed khổng lồ subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Stack Exchange Network
Site design / logo sản phẩm © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. Rev2023.1.5.43140