Sub Promotion

?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 수정 삭제
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 수정 삭제
Extra Form
제목 carolehuynh@gmail.com
예약자 21|@|2994|@|46735
vintage_white_bed-1000x667.jpgPlugins that clean up all the garbage are one of the best. If you are developing a plugin that adds something to the WordPress database, you need to make sure that it removes after itself all unwanted or unused data during the uninstall process. In this guide, we will look at useful methods for this related to the uninstall.php file. How uninstall.php works Usually you need to add the uninstall.php file to the main (root) directory of the plugin. For example, you have a plugin called Add Data to WP Database, and its main directory is / add-data-wp-database /. In this directory we can add the uninstall.php file with the following code: 01 /add-data-wp-database/ 02 /add-data-wp-database.php 03 /index.php 04 /uninstall.php <--- here it is. 05 /readme.txt Now, when uninstalling (removing) the plugin through the Plugins screen in the admin panel, WordPress will find and execute uninstall.php. This approach allows plug-in developers to remove any unwanted or unused data from the database. Here's how it works in a nutshell. For more information, you can refer to the WP Code. What code is suitable for placement in uninstall.php The uninstall.php file may contain any code necessary for the correct procedure for removing the plugin. Be sure to include code that protects the file from unwanted access. Here is an easy way to do this: 01 <?php // exit if uninstall constant is not defined 02 if (!defined('WP_UNINSTALL_PLUGIN')) exit; These lines should be located at the very beginning of uninstall.php before any other code. The code checks the constant WP_UNINSTALL_PLUGIN, which is determined by WordPress immediately before loading uninstall.php. If someone tries to access the file from the side, the script will immediately end. To give you a better idea, here is an example uninstall.php file that removes several data types. Note that most of the code is excluded for clarity: 01 <?php // exit if uninstall constant is not defined 02 if (!defined('WP_UNINSTALL_PLUGIN')) exit; 03 04 // remove plugin options 05 06 // remove plugin transients 07 08 // remove plugin cron events 09 10 // ..etc., based on what needs to be removed This shows that the approaches in terms of code are highly dependent on the data that needs to be deleted or changed. The code will vary from plugin to plugin. You need to know exactly what data you want to delete before using the appropriate technique. In the following sections of this guide, we will look at methods for removing all data types from a WordPress database. Removing plug-in options (parameters) The most popular method for deleting plugin parameters is the delete_option () function. For example, to remove a parameter called myplugin_options, add the following code to the uninstall.php file: 01 // delete plugin options 02 delete_option('myplugin_options'); Or, if you have several options to delete, use an array: 01 // delete multiple options 02 $options = array( 03 'myplugin_option_1', 04 'myplugin_option_2', 05 'myplugin_option_3', 06 ); 07 foreach ($options as $option) 08 if (get_option($option)) delete_option($option); 09 Just rename the elements of the array (for example, myplugin_option_1, etc.), specifying the options of your plugin that you want to remove. Everything is simple! Removing plugin transients Another common approach is to remove all transient plugins from the database. To do this, we can use the delete_transient () function: 01 // delete plugin transient 02 delete_transient('myplugin_transient'); If you need to remove several transients, then you can use the array: 01 // delete multiple transients 02 $transients = array( 03 'myplugin_transient_1', 04 'myplugin_transient_2', 05 'myplugin_transient_3', 06 ); 07 foreach ($transients as $transient) 08 delete_transient($transient); 09 Just rename the elements of the array (for example, myplugin_transient_1, etc.), indicating the transients of your plugin that you want to remove. Delete cron events The following methodology shows how to remove cron events using the wp_unschedule_event () function. Here is an example: 01 // delete cron event 02 $timestamp = wp_next_scheduled('myplugin_cron_event'); 03 wp_unschedule_event($timestamp, 'myplugin_cron_event'); The trick here is to use wp_next_scheduled () to get the correct $ timestamp value for the event you want to delete. Deleting database tables One of my favorite techniques. Be careful with her. Make sure the table name is correct. Here is an example of how to delete a table called myplugin_table: 01 // delete database table 02 global $wpdb; 03 $table_name = $wpdb->prefix .'myplugin_table'; 04 $wpdb->query("DROP TABLE IF EXISTS $table_name"); The technique uses the wpdb class to determine $ table_name, after which the table is deleted if it exists. Again, it is very important to replace myplugin_table with the correct name of the table you want to delete. No other code changes are required. Check everything very carefully! Delete posts and pages To delete a post or page, we can use wp_trash_post (). For example, to delete a post with ID 44, we need the following code: 01 // delete post id 44 02 wp_trash_post(44); The trick of this technique is to determine the correct ID for the page or post. There are several ways to do this. The easiest way is to save the ID of any posts and pages that are added by your plugin. For example, if your plugin adds three pages upon first activation, you can add the ID of these pages to the database as an option. Then you can turn to these options and get the correct posts to delete. In code, it looks something like this: 01 // delete pages 02 $myplugin_pages = get_option('myplugin_pages'); 03 if (is_array($myplugin_pages) && !empty($myplugin_pages)) 04 foreach ($myplugin_pages as $myplugin_page) 05 wp_trash_post($myplugin_page); 06 07 Here we use get_option () to get our array of page IDs. Then we iterate over the array and use wp_trash_post () to delete each item. Please note that this technique can be used to delete any type of posts, not just pages. Removing custom post types Here we will focus on the removal of posts that are defined as an arbitrary post type (CPT). Accordingly, we do not delete the record type itself, but all records that are of this type. To do this, we can use the wp_delete_post function. Here is an example of how to delete all entries that are of arbitrary type myplugin_cpt: 01 // delete custom post type posts 02 $myplugin_cpt_args = array('post_type' => 'myplugin_cpt', 'posts_per_page' => -1); 03 $myplugin_cpt_posts = get_posts($myplugin_cpt_args); 04 foreach ($myplugin_cpt_posts as $post) 05 wp_delete_post($post->ID, false); 06 Here we use get_posts to get all entries that are of the arbitrary type myplugin_cpt. Then we cycle through the results and use wp_delete_post to delete each record of this type. The only thing you need to change in the code is the name (slug) of an arbitrary record type, myplugin_cpt. And a reminder: make sure that the user really wants to delete all their records of this arbitrary type. You can add a separate option for this. Note: The wp_delete_post function deletes not only all entries, but also everything that is attached to them, including comments, metadata, terms, etc. The second parameter, wp_delete_post, is set to false. This means that the post will be moved to the Trash, from where the user will be able to restore it later if desired. If you want to delete posts without a basket, then change this parameter to true. Removing user metadata To delete custom metadata, use the delete_user_meta () function. For example, to delete all the myplugin_user_meta metadata, specify the following code: 01 // delete user meta 02 $users = get_users(); 03 foreach ($users as $user) 04 delete_user_meta($user->ID, 'myplugin_user_meta'); 05 Here we use get_users () to get an array of users.

Then we go through the array v5.5.2 - Multi Rating Pro Nulled 5.5.1 – WordPress Rating and Feedback Plugin use delete_user_meta to delete all user metadata called myplugin_user_meta. Thus, Divi Supreme v.2.9.4 Nulled – Custom and Creative Divi Modules to use this technique, v.1.8.2.6 Divi Mega Pro The Ultimate Divi Mega Menu Builder Full Download simply put in place of myplugin_user_meta the name of your metadata that you want to delete. Note: if you want to delete metadata from a specific subset of users, then in this case you need to refer to WP_User_Query :: v1.4.1 - Blggn Nulled – A Responsive Blog & Shop WordPress Theme v.1.4.0 prepare_query ().

List of Articles
번호 제목 글쓴이 최근 수정일 날짜
72106 mervin_hoag@gmail.com MervinHoag314935 2020.06.10 2020.06.10
72105 elkecarrell@aol.com ElkeCarrell09406656 2020.06.10 2020.06.10
72104 maynardbarlee@gmail.com MaynardK316849965244 2020.06.10 2020.06.10
72103 marianawhiddon@gmail.com MarianaWhiddon711759 2020.06.10 2020.06.10
72102 patricegossett@gmail.com PatriceGossett140 2020.06.10 2020.06.10
72101 brandendaugherty@arcor.de BrandenDaugherty8475 2020.06.10 2020.06.10
72100 roxannanesbitt@aol.com RoxannaNesbitt86 2020.06.10 2020.06.10
72099 concepcionbalmain@t-online.de ConcepcionBalmain28 2020.06.10 2020.06.10
72098 brentonjohansen@zoho.com BrentonJohansen54 2020.06.10 2020.06.10
72097 jacquieworrall@gmail.com JacquieP3644914082432 2020.06.10 2020.06.10
72096 kierancreech@gawab.com KieranCreech04501 2020.06.10 2020.06.10
72095 jeremiahwillson@inbox.com JeremiahWillson8 2020.06.10 2020.06.10
72094 christinastaton@arcor.de ChristinaStaton4943 2020.06.10 2020.06.10
72093 effiecarone@yahoo.com EffieY018130499454247 2020.06.10 2020.06.10
72092 raekemble@freenet.de RaeC333798661299439 2020.06.10 2020.06.10
72091 warrenhooker@inbox.com WarrenU89220958095 2020.06.10 2020.06.10
72090 leonoramakin@gmail.com LeonoraMakin90844 2020.06.10 2020.06.10
72089 lillie_raynor@aol.com LillieRaynor8552396 2020.06.10 2020.06.10
72088 rileyosburne@zoho.com RileyOsburne2432 2020.06.10 2020.06.10
72087 jan.reynell@yahoo.de JanReynell1565119869 2020.06.10 2020.06.10
72086 nigeltribolet@yahoo.de NigelTribolet1803672 2020.06.10 2020.06.10
72085 jerricruickshank@inbox.com CQWJerri8779277366 2020.06.10 2020.06.10
72084 philliskeegan@web.de UGGPhillis6936393728 2020.06.10 2020.06.10
72083 giselekarr@mailingaddress.org VUPGisele655714558 2020.06.10 2020.06.10
72082 alinaosman@arcor.de AlinaOsman44876204 2020.06.10 2020.06.10
» carolehuynh@gmail.com CaroleHuynh77066259 2020.06.10 2020.06.10
72080 callie.rider@inbox.com CallieRider63674174 2020.06.10 2020.06.10
72079 josetteplath@gmail.com JosettePlath9008267 2020.06.10 2020.06.10
72078 joeygiles@gmail.com JoeyGiles4370026486 2020.06.10 2020.06.10
72077 fernehardey@peacemail.com FerneHardey1968 2020.06.10 2020.06.10
72076 dannyeisenhower@gmail.com DannyEisenhower0495 2020.06.10 2020.06.10
72075 seanheady@yahoo.com SeanEhd64195233577529 2020.06.10 2020.06.10
72074 ashtondegaris@gmx.net AshtonDeGaris081859 2020.06.10 2020.06.10
72073 antoniettasherry@gmail.com AntoniettaBnu915518 2020.06.10 2020.06.10
72072 chancemobley@yahoo.com Chance720498311182341 2020.06.10 2020.06.10
72071 chanelgower@gmail.com HATChanel5556275 2020.06.10 2020.06.10
72070 terrence_upjohn@gmail.com TerrenceUpjohn7 2020.06.10 2020.06.10
72069 bianca.masel@4email.net BiancaMasel78811 2020.06.10 2020.06.10
72068 roseannletcher@live.de RoseannLetcher9294 2020.06.10 2020.06.10
72067 octaviastrayer@arcor.de OctaviaStrayer89682 2020.06.10 2020.06.10
72066 caitlynstralia@bigstring.com CaitlynStralia4 2020.06.10 2020.06.10
72065 nelly_noskowski@inbox.com NellyNoskowski97 2020.06.10 2020.06.10
72064 chasewynn@hotmail.de ChaseWynn8675336166 2020.06.10 2020.06.10
72063 julie.wilmoth@freenet.de Julie69V2449209 2020.06.10 2020.06.10
72062 leonida.coy@aol.com LeonidaCoy005891 2020.06.10 2020.06.10
72061 mollyguidry@web.de SAEMolly181564697905 2020.06.10 2020.06.10
72060 vincerepin@bigstring.com VinceQty2758833 2020.06.10 2020.06.10
72059 gisele.lamontagne@web.de LPGGisele32417088676 2020.06.10 2020.06.10
72058 ben_louis@fastmessaging.com BenLouis579043973173 2020.06.10 2020.06.10
72057 starlaskillen@gmail.com StarlaZ686341558 2020.06.10 2020.06.10
Board Pagination Prev 1 ... 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 ... 4736 Next
/ 4736

bodum2ro 43,sejong, Korea / Copyrightⓒ. All Rights Reserved By fone

© k2s0o1d4e0s2i1g5n. All Rights Reserved