logo

  • Hỏi Đáp
  • Kiến Thức
  • Sức Khỏe
  • Tử Vi
  • Công Nghệ
No Result
View All Result
logo
No Result
View All Result
Trang chủ uninstall

Uninstall

by Admin _ January 09, 2023
I am trying khổng lồ write a simple plugin that, among other things, creates a custom post type.I have been searching everywhere but I have really no idea on how lớn write the uninstall function that delete the custom post type và all its entries from the db.

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);
chia sẻ
Improve this question
Follow
edited Aug 8, năm trước at 11:15
antonio83
asked Aug 8, 2014 at 8:04

*

antonio83antonio83
42433 silver badges99 bronze badges
2
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)
1
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.

Xem thêm: Bệnh Phụ Nữ Băng Huyết Là Gì?Tìm Hiểu Nguyên Nhân Tìm Hiểu Nguyên Nhân

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);
cốt truyện
Improve this answer
Follow
answered Aug 9, 2014 at 3:29

*

Adam ErstelleAdam Erstelle
2,41433 gold badges2121 silver badges3535 bronze badges
1
add a phản hồi |

Your Answer


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.


Draft saved
Draft discarded

Sign up or log in


Sign up using Google
Sign up using Facebook
Sign up using e-mail and Password
Submit

Post as a guest


Name
e-mail Required, but never shown


Post as a guest


Name
thư điện tử

Required, but never shown


Post Your Answer Discard

By clicking “Post Your Answer”, you agree khổng lồ our terms of service, privacy policy and cookie policy


Not the answer you're looking for? Browse other questions tagged or ask your own question.
The Overflow Blog Featured on Meta
Related
635
Can I install/update WordPress plugins without providing FTP access?
3
wordpress mysql - delete all custom post type
4
Order by custom field (numeric) in WP_Query
0
Wordpress custom metabox, load on posts, pages, & all custom post types?
0
Mysql Left OUTER JOIN with Subquery (wordpress)
1
wordpress kiến thiết pattern name
Hot Network Questions more hot questions

Question feed
Subscribe to lớn RSS
Question feed khổng lồ subscribe to this RSS feed, copy and paste this URL into your RSS reader.


*

lang-php
Stack Overflow
Products
Company
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


Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device & disclose information in accordance with our Cookie Policy.

Share Tweet Linkedin Pinterest
Previous Post

Database: seeding

Next Post

Chuyển mảng 2 chiều thành 1 chiều php

CÙNG CHUYÊN MỤC

form register php

Form register php

09/04/2021
fantastic blog (cms) in php with source code

Fantastic blog (cms) in php with source code

28/04/2021
validate form php javascript

Validate form php javascript

28/04/2021
http diendanlequydon com viewtopic php style 6

Http diendanlequydon com viewtopic php style 6

28/04/2021
cách cài đặt php 7

Cách cài đặt php 7

24/01/2023
rövid videó

Rövid videó

23/01/2023
installing apache php mysql on ubuntu 18

Installing apache php mysql on ubuntu 18

20/01/2023
tính kế thừa trong oop php

Tính kế thừa trong oop php

20/01/2023

Newsletter

The most important automotive news and events of the day

We won't spam you. Pinky swear.

Chuyên Mục

  • Hỏi Đáp
  • Kiến Thức
  • Sức Khỏe
  • Tử Vi
  • Công Nghệ

News Post

  • Mang thai tháng cuối đau cửa mình

About

Chúng tôi tạo ra trang web nhằm mục đích mang lại kiến thức bổ ích cho cộng đồng, các bài viết được sưu tầm từ nhiều nguồn trên internet giúp mang lại kiến thức khách quan dành cho bạn

©2023 darkedeneurope.com - Website WordPress vì mục đích cộng đồng

Liên Hệ - Giới Thiệu - Nội Quy - Bảo Mật

No Result
View All Result
  • Trang chủ
  • Chuyên mục
    • Hỏi Đáp
    • Kiến Thức
    • Sức Khỏe
    • Tử Vi
    • Công Nghệ
  • Lưu trữ
  • Liên hệ

© 2023 darkedeneurope.com - Website WordPress vì mục đích cộng đồng.