Create a WordPress Plugin from Scratch - Part 5 - Uninstall Hook

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ธ.ค. 2024

ความคิดเห็น • 141

  • @drmfurqan
    @drmfurqan 7 ปีที่แล้ว +34

    Hi Alex
    First of all, Thank you for the hardwork and efforts you put in your videos. I am learning alot from your channel.
    I have a few ideas for refactoring the code a little in this particular video
    First: instead of hard coding wp_posts table in query can we use $table_prefix with table name. because a large number of wordpress installation scripts usually change the table prefix of table in wordpress database.
    e.g
    global $wpdb;
    global $table_prefix;
    $wpdb->query("DELETE FROM " . $table_prefix . "posts WHERE post_type = 'book'");
    SECOND:
    $wpdb->query("DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT id FROM wp_posts)" );
    The above code will delete all meta detas of IDs not present in wp_post, this will also delete meta data of those posts which were not created by our plugin custom post? may be a good thing but I dont think it is what uninstallation of this plugin intended.
    can we first clear the meta data of our post type then delete records of our posts from wp_posts table
    global $wpdb;
    global $table_prefix;
    $posts = $table_prefix . "posts";
    $meta = $table_prefix . "postmeta";
    $relationships = $table_prefix . "term_relationships";
    // Delete Meta of custom post type (book only)
    $wpdb->query("DELETE FROM " . $meta . " WHERE post_id IN (SELECT id FROM " . $posts . " WHERE post_type = 'book')");
    // Delete relationships of custom post type ( book only )
    $wpdb->query("DELETE FROM " . $relationships . " WHERE object_id IN (SELECT id FROM " . $posts . " WHERE post_type = 'book')");
    // Delete records of custom post type ( books )
    $wpdb->query("DELETE FROM " . $posts . " WHERE post_type = 'book'");

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว +9

      Hi, thanks for watching.
      Of course, you can change and update the code that I'm showing to fit your needs.
      I'm just showing you how to tap specific features of WordPress, what you write then, it's totally up to you.
      Everything you wrote sounds good.
      Happy Coding!

    • @teamrampageservices7981
      @teamrampageservices7981 2 ปีที่แล้ว +1

      @@alecaddd I would say that dealing with a production database directly as you've presented as your preferred method is a dangerous position when teaching beginners level coders. The built in methods and functions provided by WP should be used simply because of the data safe guards WP has built into those functions. Issuing a DELETE SQL command to a database is more likely to cause problems for the end users than accomplish the desired task safely, which could lead to an end user loosing data and causing serious problems. In my experience, it's the plugin developer that gets raked over the fire over a bad practice such as this.
      So far I've found great advice and practices in this series, but advocating for the use of an advanced and dangerous practice by beginning developers is sure to lead to a lot of issues and serious consequences for anyone following your course.
      Take it from a "grey-beard", the direct SQL approach is something you don't want newbies using! I learned this lesson the hard way, not only did my code cost a former client thousands of dollars in lost data but it also lost me a $10,000 contract plus loses I was responsible for!
      This video needs to be updated with the SQL method removed or just remove the video entirely, to leave this up is almost malicious! Best practices are there for a reason.

    • @Zei33
      @Zei33 ปีที่แล้ว

      This is terrible and nobody should ever do it like this. If you need to insert data, you need to bind the parameters. NEVER insert variables directly into the query string. I repeat. NEVER. If you don't know what you're doing, always bind the parameters.

  • @jfrosorio
    @jfrosorio 5 ปีที่แล้ว +2

    Alessandro, thank you so much for your tutorials. This series saved my day!

  • @mauriciosotoa8130
    @mauriciosotoa8130 3 ปีที่แล้ว

    reading some books about WordPress plugins, watching some paid courses, and this free course is the best one, at least for me.

    • @alecaddd
      @alecaddd  3 ปีที่แล้ว

      Thank you so much!

  • @babu-oh8ss
    @babu-oh8ss 7 ปีที่แล้ว +9

    Hi Alex, love your videos. I just want to say that usually i pronounce uninstall as un - install, like cooked , uncooked :)

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว +1

      Yeah, thanks for the correction, my pronunciation is still awful >_>

    • @wotw_coza
      @wotw_coza 6 ปีที่แล้ว +2

      No way, from now on I'm calling it uni stall much cooler ;)

    • @radekwysocki7875
      @radekwysocki7875 6 ปีที่แล้ว +2

      Unicooked food XD

    • @NealHill0
      @NealHill0 6 ปีที่แล้ว

      UHN-in-stall .... "UHN" the same sound as the "UHN" when you say the number "one." HOWEVER: UNI-nstall is now my favorite. I will try to use it in every professional situation possible!

  • @klaasdeeindbaas
    @klaasdeeindbaas 5 ปีที่แล้ว +1

    In the uninstall preparation (the empty uninstall function you replaced with uninstall.php) you had two note-to-self comments: 1. delete CPT, and 2. remove entries from DB. In the uninstall.php you implement code fulfilling the 2nd note-to-self, the DB cleanup, but the first, the deletion of the CPT, I don't see effectuated
    I love these tutorials you create and the comment above is not to be intended as any attempt to diminish your excellent lessons. I just noticed and wanted to notify you that you seem to forget something. Perhaps you can complete your vid with a sticky post in which you give the code to delete the CPT

  • @idlecom
    @idlecom 5 ปีที่แล้ว +2

    I didnt get the php error at the beginning. Is it possible that the uninstall hook has been improved?

  • @marclouiecabigas3771
    @marclouiecabigas3771 2 ปีที่แล้ว

    I enjoyed your tutorials and now it keep me going to watch more, i already inspired me to create my own plugin

  • @sevdamurat4455
    @sevdamurat4455 6 ปีที่แล้ว +1

    I dont know the reason and not exactly know what it is, but method using wp_delete_post does not delete 'Auto Draft' input on wp_posts table BUT second method using SQL query deletes 'Auto Draft' of custom type. ANOTHER IMPORTANT POINT: since WP allows to change table prefixes at SETUP, table prefixes may change. Thus for the sake of code portability it is safer to use the frst method instead of dealing with SQL and table names. Just a note

    • @Zei33
      @Zei33 ปีที่แล้ว +1

      That's a beautiful point and should be noted for everyone here. Custom prefixes should be taken into account.

  • @sandipanmondal9474
    @sandipanmondal9474 5 ปีที่แล้ว +1

    You are the best teacher forever.

  • @scenitdk6624
    @scenitdk6624 5 ปีที่แล้ว +1

    Hi Alessandro. Thanks for this awesome tutorials. Before I get started I really would be glad to know which tools you use while developing. which ones would you recommend? Best Trine

    • @alecaddd
      @alecaddd  5 ปีที่แล้ว

      This is a complete playlist of my entire setup: th-cam.com/video/4KBuPCeF9Gc/w-d-xo.html

  • @samardebnath6581
    @samardebnath6581 5 ปีที่แล้ว +1

    In WP codex uninstall.php has only
    $option_name = 'wporg_option';
    delete_option($option_name);
    delete_site_option($option_name);
    global $wpdb;
    $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}mytable");
    Will this code serve our purpose..?
    If so then what should I write in place of wporg_option..?

  • @sergeylukin8740
    @sergeylukin8740 2 ปีที่แล้ว

    Great tutorial series! One comment regarding deleting DB stored data during uninstall: it'd make more sense to first `DELETE from wp_postmeta WHERE post_id IN (SELECT id FROM wp_posts WHERE post_type = 'book');` and then `DELETE FROM wp_posts WHERE post_type = 'book';` to make sure we only delete data related to our plugin and leave garbage collection to the system/user land.

    • @alecaddd
      @alecaddd  2 ปีที่แล้ว

      Yes, that makes sense.
      In general my tutorials are not "production" ready, as I mostly focus on showing various use cases on how to build something and how to use some specific WP features. Then you (as the developer watching) can build on top of that knowledge and improve to achieve what you need thanks to the basics I just showed.
      Thanks for watching :D

  • @matinhewing1
    @matinhewing1 2 ปีที่แล้ว +1

    Hi! Great tutorial! Out of interest, where did you learn to code? A degree? Or self taught? Thanks!

    • @alecaddd
      @alecaddd  2 ปีที่แล้ว

      I studied design originally, but I got very interested in coding so I was going to design school in the morning and learning PHP by myself during nights.
      I wouldn't recommend it :P

  • @sampsonorson
    @sampsonorson 6 ปีที่แล้ว +2

    Fantastic tutorial! For deletion, i would suggest we delete from the leaves. This is my opinion on how we could delete wp_term_relationships.
    DELETE FROM wp_term_relationships WHERE term_taxonomy_id IN (
    SELECT a.term_taxonomy_id
    FROM wp_term_relationships AS a
    INNER JOIN wp_posts AS b ON b.ID = a.object_id
    WHERE b.post_type = 'book'
    )

    • @alecaddd
      @alecaddd  6 ปีที่แล้ว

      Thanks for sharing :D

  • @mounsec1406
    @mounsec1406 6 ปีที่แล้ว +4

    Hi alessandro, 🤔 if I use the second method, I risk to delete any post_meta that belong to other eventual CPT (for example products, clients, and so on), if i change queries like this, isn't better?
    // Delete postmeta only for book cpt
    $wpdb->query( "DELETE FROM ".$wpdb->prefix."postmeta WHERE post_id IN (SELECT id FROM ".$wpdb->prefix."posts WHERE post_type = 'book')" );
    // Delete terme relationships also with book cpt
    $wpdb->query( "DELETE FROM ".$wpdb->prefix."term_relationships WHERE object_id IN (SELECT id FROM ".$wpdb->prefix."posts WHERE post_type = 'book')" );
    // and now that i didn't need anymore books elements ID, i delete them!
    $wpdb->query( "DELETE FROM ".$wpdb->prefix."posts WHERE post_type = 'book'" );
    Thank you 😁

    • @cnvemrede
      @cnvemrede 5 ปีที่แล้ว

      It worked for me. Thanks!

  • @MichHusker
    @MichHusker 4 ปีที่แล้ว +1

    First, let me say thank you for all the information you're laying out, It leads to even more insight. I appreciate your time and effort.
    Do lines 23 and 24 need to be changed from 'SELECT id' to 'SELECT ID'?

    • @MichHusker
      @MichHusker 4 ปีที่แล้ว +1

      I'll answer my own question, yes, id needs to be capitalized. It's good coding practice. Also it's mandatory in some situations. More details at:
      dev.mysql.com/doc/refman/8.0/en/identifier-case-sensitivity.html

    • @shadivanslim366
      @shadivanslim366 4 ปีที่แล้ว

      @@MichHusker thanks buddy

  • @deathlikecote
    @deathlikecote 5 ปีที่แล้ว +2

    Hi Alex, thanks for your lesson, i'm so very interested. I have question about $wpdb->query.. if user don't use "wp_" as table name preffix. What code should be write?
    Thx Alex

    • @ko4594
      @ko4594 4 ปีที่แล้ว

      That’s why it’s better to use wp_delete_post function.

    • @StefanSchmalhaus
      @StefanSchmalhaus 2 ปีที่แล้ว +1

      You can use $wpdb->prefix:
      $wpdb->query( "DELETE FROM {$wpdb->prefix}posts WHERE post_type = 'book'" );
      $wpdb->query( "DELETE FROM {$wpdb->prefix}postmeta WHERE post_id NOT IN (SELECT id FROM {$wpdb->prefix}posts)" );
      $wpdb->query( "DELETE FROM {$wpdb->prefix}term_relationships WHERE object_id NOT IN (SELECT id FROM {$wpdb->prefix}posts)" );

  • @GladaKalle
    @GladaKalle 7 ปีที่แล้ว +1

    Hi Alex!
    About the first method of deleting the plugin (foreach-loop) what's the best approach of writing good OOP code for also
    include of deleting multiple metaboxes and taxonomy related to the Custom post type ?
    Again, many thanks to your great tutorials! :)

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว

      I will tackle a similar situation in future videos. Thanks for watching, cheers

    • @GladaKalle
      @GladaKalle 7 ปีที่แล้ว

      OK :) For the second method of deleting the plugin I cannot seem to get rid of the terms for the CPT.
      Everything else is simply removed but the terms is still there in the database table. I've use your code and
      i thought that the line "DELETE FROM www1_term_relationships" would accomplish that?
      What am i missing here and how can i delete every related terms for the taxonomy?

  • @marcelloperri183
    @marcelloperri183 5 ปีที่แล้ว

    Ciao Alessandro, grazie per il tuo lavoro.
    What would happen if another plugin create a custom post type called 'book' when the post type book already exists in the database?
    And I want the plugin to create a view for the new custom post type, the view has to be installed by the plugin, how can I make it?
    Thanks

  • @nikunjmunjani4164
    @nikunjmunjani4164 7 ปีที่แล้ว +2

    Nice Tutorial !!!!!!! Thanx for Starting This Series.....:)

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว

      Thanks for watching :D

  • @sudhakarsudha9655
    @sudhakarsudha9655 7 ปีที่แล้ว +1

    excellent after woocommernce theme tutorial can you give tutorials for what are the things should we know in wordpress database

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว +1

      Analyzing the WP DB...interesting. I'll add it to the list for future tutorials

    • @sudhakarsudha9655
      @sudhakarsudha9655 7 ปีที่แล้ว

      yahoo! i am delighted

  • @jounalansman1769
    @jounalansman1769 3 ปีที่แล้ว +1

    Thanks for the great video series. I would also like to add that it is pronounced un-install :)

  • @vigilancer
    @vigilancer 7 ปีที่แล้ว +1

    Finished! Will watch next video!

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว

      +Brian Coolidge great

  • @howihearfinland
    @howihearfinland 7 ปีที่แล้ว +1

    Hey, awesome tutorial! I started to study how to write my own plugins awhile ago so the timing for this series is perfect! :) I have one question. Lots of plugin developers use singleton pattern and even after googling about it I still feel like I don't understand it. Is this something you gonna talk about in upcoming episodes?

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว +2

      Hi, thank you so much for watching.
      I'm a bit against Singleton Design Pattern, it's mostly a personal choice, but I can see why developers like to use it.
      A singleton is simply a class that can be instantiated only once, and if you try to instantiate it again, it returns the previous instance without creating a new one.
      A Singleton is useful and should be used when dealing with a class that can't be instantiated more than once, like a Database connection, or a Log file system.
      If I have to do something like that in my plugin for a class that it's not a DB connection or a LOG system, I prefer to use a Factory pattern approach. Basically, a class that wraps the class I want to initialize, initialize it for me, and if I need it again and it was already initialized, returns the shared instance of that object.
      If you want to extend this conversation, you can come to the forum and we can share code examples.
      I will definitely talk about this more in future lessons.
      Cheers

    • @howihearfinland
      @howihearfinland 7 ปีที่แล้ว

      Thank you for fast and thorough answer :) I'm happy to hear that you are gonn talk about this in future lessons. Can't wait!

  • @briandahlstroem
    @briandahlstroem 7 ปีที่แล้ว +1

    Super tutorial👍
    But - What if the user of our plugin have given the tabels in the database of wordpress another prefix example: vh23_ .
    How do you fix that in the query string.

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว

      I will tackle it in future lessons when we'll actually build a real plugin, but the short answer is to use the $wpdb->prefix, that automatically returns the prefix selected by the user.
      So in our case, you can select the table in this way: $wpdb->prefix . 'posts';

    • @briandahlstroem
      @briandahlstroem 7 ปีที่แล้ว

      Thanks
      Keep up with the good work :-)

  • @RussDnB
    @RussDnB 4 ปีที่แล้ว

    Similar to the ABSPATH a few lessons back, could we also uninstall with something like: defined ( 'WP-UNINSTALL_PLUGIN' ) or die(); ?

  • @cjfranca2004
    @cjfranca2004 ปีที่แล้ว

    2023 I studying and is very well, but the menu book not hide when I desable the plugin. Can help me, please ?

  • @armekh1
    @armekh1 7 ปีที่แล้ว +4

    Alex, Thank you for amazing tutorial.
    How does our uninstall.php connect to alecaddd-plugin.php ? isn't it necessary ?

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว +7

      I think I said it in the video. You don't need to hook it anywhere. If you name that final exactly uninstall.php, WordPress will recognize it as part of the plugin structure and use it automatically on plugin uninstall.

    • @armekh1
      @armekh1 7 ปีที่แล้ว

      Thanks very much!

  • @asimah3959
    @asimah3959 6 ปีที่แล้ว

    Does wp_posts contain other posts that are created by another plugin? Also will this query delete those unintended posts?

  • @zaguerinho
    @zaguerinho 4 ปีที่แล้ว +1

    What IDE are you using?

    • @alecaddd
      @alecaddd  4 ปีที่แล้ว +1

      Sublime Text 3

  • @vcrohithutagonna2105
    @vcrohithutagonna2105 ปีที่แล้ว

    How do I get snippets for wp. I am not getting any of those

  • @mahawaqar8702
    @mahawaqar8702 3 ปีที่แล้ว

    My custom post types are not appearing over left wp-admin menu. Can anyone guide me about that?

  • @mahmoudhossameldin2932
    @mahmoudhossameldin2932 7 ปีที่แล้ว

    Thanks for the series, I also have a question. sorry if it is out of the topic but I'd like if you can help.
    the responsive images in WordPress are automatically being done if it is a post. I wonder how to apply this method to a custom page template?

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว

      If I got your question right, it's just a CSS attribute for the images to set a max-width: 100% and height: auto.
      I did a lot of tutorials about proper responsive styling and many other tricks in the Premium Development Series.
      Check that playlist.
      Cheers

    • @mahmoudhossameldin2932
      @mahmoudhossameldin2932 7 ปีที่แล้ว

      Alessandro Castellani well, i will check it. Thanks man 😃

  • @deanallen6888
    @deanallen6888 6 ปีที่แล้ว

    tnx for your amazing videos .
    whats your editor?

  • @tonycaterev1341
    @tonycaterev1341 5 ปีที่แล้ว

    Hey Alex, thanks for the great tutorial!
    One question to the $wpdb method: Would it make sense to work with an $wpdb->prepare() before set the query, for security reasons? Or is this step not necessary in a custom plugin?

    • @Zei33
      @Zei33 ปีที่แล้ว

      I know it's late, but you're absolutely correct. If you intend to insert data into the query, you should be binding your parameters. The only time this kind of thing is acceptable is if it's a static query that has no dynamic elements to it.

  • @Omeostatica
    @Omeostatica 7 ปีที่แล้ว +1

    I suppose that the latter method is better in performances than the former, because it goes directly on the database and destroy all data that aren't useful anymore.
    What do you think about?

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว

      Didn't fully test the performance, but in future lessons, I will use it in a real situation and define the final method that I like to use. Cheers

  • @lilitgrigoryan6020
    @lilitgrigoryan6020 5 ปีที่แล้ว

    Thanks you very much just I want to understand $wpdb->query("DELETE FROM wp_postmeta WHERE post_id NOT IN(SELECT id FROM wp_posts)");
    $wpdb->query("DELETE FROM wp_term_relationships WHERE object_id NOT IN(SELECT id FROM wp_posts)");
    this part.Is it mean to delete everthing in wp_postmeta and wp_term_relationships tables which is not connect to data stored in wp_posts table?and consequency to delete in those 2 tables every data connect 'books' post type.

  • @eng.alitaha
    @eng.alitaha 2 ปีที่แล้ว

    Its working , thanks my teacher

  • @vanshikamittal2412
    @vanshikamittal2412 4 ปีที่แล้ว

    Hi Alex, I have a question.
    In any of the previous videos, we haven't created any database so is this the pre-built database or what?
    If yes, then please tell me how to locate it.
    Hoping for an early reply!!!!!!

    • @mdeshan5116
      @mdeshan5116 4 ปีที่แล้ว

      Yes Pre auto built through wordpress installation. Locate it by using phpmyadmin in xampp

  • @Thesmshiplu
    @Thesmshiplu 3 ปีที่แล้ว

    just loving you bro!

  •  3 ปีที่แล้ว

    why didnt delete postmeta firstly before from posts ?

  • @kamalsahmoud9909
    @kamalsahmoud9909 6 ปีที่แล้ว +1

    deleting data after deactivate plugin not working for me, i have the some code and last version wordpress at this time.

    • @siddhusathi
      @siddhusathi 6 ปีที่แล้ว

      got the any answer? if u know tell me.

    • @ibrahimhalouane8130
      @ibrahimhalouane8130 4 ปีที่แล้ว

      Looking at 1:20 he's using v4.8.1, is that version yours?

  • @nobir98
    @nobir98 7 ปีที่แล้ว

    get_posts() not working ... I use var_dump to see what inside this function but it triggers an error :(
    Fatal error: Uncaught Error: Call to undefined function get_posts() in .....\wp-content\plugins
    obirplugin\uninstall.php
    Error: Call to undefined function get_posts() in .....\wp-content\plugins
    obirplugin\uninstall.php
    This two error shows me :(

  • @sevdamurat4455
    @sevdamurat4455 6 ปีที่แล้ว

    is not it a related tables wp_posts and wp_postmeta. Doesn't wp_postmeta deletes automatically when you deleted related post from wp_posts table?. (foreign key relation?)

    • @sevdamurat4455
      @sevdamurat4455 6 ปีที่แล้ว

      I mean is not there a cascading relation among them?

    • @alecaddd
      @alecaddd  6 ปีที่แล้ว

      It doesn't seem like it

  • @christopherjaya342
    @christopherjaya342 ปีที่แล้ว

    Btw always use $wpdb->prepare() before make query for $wpdb->query(), to prevent SQL injection

  • @sldev8311
    @sldev8311 6 ปีที่แล้ว

    what's your wordpress function snippets plugin in this IDE. (i think IDE is Atom)

    • @alecaddd
      @alecaddd  6 ปีที่แล้ว +1

      I'm using Sublime Text 3 with the WordPress Hooks and Autocomplete package.

    • @sldev8311
      @sldev8311 6 ปีที่แล้ว

      thank you..

  • @madhukarmisra8982
    @madhukarmisra8982 3 ปีที่แล้ว

    Super work.

  • @nafeulrifat
    @nafeulrifat 7 ปีที่แล้ว +2

    Hey Alex, Thanks for your tutorial. But I want to know about, you type...
    $wpdb->query( "DELETE FROM wp_posts WHERE post_type = 'book'" );
    $wpdb->query( "DELETE FROM wp_postmeta WHERE post_id NOT IN ( SELECT id FROM wp_posts )" );
    $wpdb->query( "DELETE FROM wp_term_relationships WHERE object_id NOT IN ( SELECT id FROM wp_posts )" );
    But what else if database table prefix is not set to 'wp_'?? Just for example, someone type to his database table prefix to 'wpsomething_', so how can I run my action??

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว +2

      +Nafeul Rifat you can access the globally stored table prefix with this code.
      global $wpdb;
      // Current site prefix
      echo $wpdb->prefix;
      You can simply replace your table names in the SQL query with ' . $wpdb->prefix . '_posts ...

    • @nafeulrifat
      @nafeulrifat 7 ปีที่แล้ว

      Now it looks better then previous :)

    • @BoegiTube
      @BoegiTube 7 ปีที่แล้ว

      Sorry - A part of my comment was wrong... Thanks for the tutorial series... Anyway - Please keep in mind that some wordpress installations might use a different WP Prefix

    • @khrazy5150
      @khrazy5150 6 ปีที่แล้ว

      Instead of using the prefix attribute with the dot notation to append the SQL string which is prone to errors, why not use the table attribute and intercalate it in the string instead?
      "DELETE FROM {$wpdb->postmeta} WHERE post_id NOT IN (SELECT id FROM {$wpdb->posts})";

  • @hassanamz7038
    @hassanamz7038 4 ปีที่แล้ว

    Uni-style or un- install

  • @nobir98
    @nobir98 7 ปีที่แล้ว

    can I use
    defined( 'ABSPATH' );
    intend of
    !defined( 'WP_UNISTALL_PLUGIN' ); ??

    • @RudyGayRaptors
      @RudyGayRaptors 6 ปีที่แล้ว

      No, if you do so, some other plugins can just call your uninstall.php page and screw up your plugin

  • @ananyamahapatra6597
    @ananyamahapatra6597 5 ปีที่แล้ว

    U r d best buddy😎🥳
    Thanks for the help🙂

  • @nobir98
    @nobir98 7 ปีที่แล้ว

    if user change wp prefix .... then what to do ?

    • @nobir98
      @nobir98 7 ปีที่แล้ว +1

      no need to ans this question I already found this ans in your comment sections :D
      thanks :D

  • @johnkramer2282
    @johnkramer2282 6 ปีที่แล้ว

    somehow my uninstall.php file wont trigger if i uninstall the plugins

    • @alecaddd
      @alecaddd  6 ปีที่แล้ว

      Did you put it in the base directory of the plugin?
      If it doesn't work at all, you can use the uninstall hook method as an alternative.
      developer.wordpress.org/reference/functions/register_uninstall_hook/

  • @tahsinurrahman8776
    @tahsinurrahman8776 5 ปีที่แล้ว

    "Could not fully remove the plugin.." why is this problem occurring?

    • @alecaddd
      @alecaddd  5 ปีที่แล้ว +1

      Check my source code on GitHub

    • @tahsinurrahman8776
      @tahsinurrahman8776 5 ปีที่แล้ว

      @@alecaddd Thanks. I tried but still showing that error.

  • @pavanlulla
    @pavanlulla 5 ปีที่แล้ว

    The danger of assumptions.. wp table names can have a custom prefix for security. So the sql will not work and give an error.

    • @alecaddd
      @alecaddd  5 ปีที่แล้ว

      This is just an example, you can get the table prefix from the env file or the config file.

  • @dyanbonke
    @dyanbonke 6 ปีที่แล้ว +1

    Awesome.

  • @TimothyCareyDV
    @TimothyCareyDV 6 ปีที่แล้ว +1

    You have a document for the text of this video. For all you typed in.

    • @alecaddd
      @alecaddd  6 ปีที่แล้ว

      Yes, my entire course code is available on my GitHub repository. There's a link in the description

    • @TimothyCareyDV
      @TimothyCareyDV 6 ปีที่แล้ว

      I had created WordPress plug ins before. I haven't used object oriented programming on WordPress. Actually not since college in 1998. I never understood it then, but your videos helped me. I made a plug in for in the dashboard (admin) that had different pages with different tabs of information that just add the different tabs in that admin area. It used get and post type form queries. I'd like to do the same, but on the front end instead of the backend. I must be missing some little detail. But I'm also going to try object oriented because I might need to extend the program at some point. I have to also use custom post types. Can you help guide me where to find my missing information on front end instead of back end.

  • @8BlankWolf8
    @8BlankWolf8 7 ปีที่แล้ว +1

    Hey Alessandro it's me again.
    I think your sql deletions are a bit ... to drastic. Instead I would do something like this:
    DELETE FROM wp_postmeta WHERE post_id IN (SELECT id FROM wp_posts WHERE post_type = 'book')
    DELETE FROM wp_posts WHERE post_type = 'book'
    In my case you really only delete what did came from your plugin and not any funcy data that may or may not be used by something. I did check the MYSQL table relationship constrains in the current downloadable version of Wordpress and there aren't constrains.
    Greetings BlankWolf

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว

      Sure thing! ;D

  • @vishalchavda5766
    @vishalchavda5766 7 ปีที่แล้ว +1

    You r aaawesome:D

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว +1

      Thank you so much :D

  • @lincolnmyth1342
    @lincolnmyth1342 5 ปีที่แล้ว +1

    UN INSTALL not UNI stall

  • @dyanbonke
    @dyanbonke 6 ปีที่แล้ว +3

    I think ....i will join those who call un-install unistall.....cool. Happy coding. :)

    • @alecaddd
      @alecaddd  6 ปีที่แล้ว

      Ahahaha, I know, sorry, my pronunciation is terrible

  • @nobir98
    @nobir98 7 ปีที่แล้ว +1

    :D nice Alex brother :D

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว +1

      Thanks

  • @protonalex
    @protonalex 7 ปีที่แล้ว

    The prefix "wp_posts" can be different!

    • @alecaddd
      @alecaddd  7 ปีที่แล้ว +2

      I know, this was just an example. You can get the current DB prefix with this code:
      global $wpdb;
      // Current site prefix
      echo $wpdb->prefix;

  • @Schjoenz
    @Schjoenz ปีที่แล้ว

    It's 6 years ago BUT, "you-nin-stall"?? it should be "ann-in-stall".. Not youninstall. "un" is read as "ann" in English. But your lessons are great. I'm just nitpicking on how you say the word and I can't stop from thinking about it unless I comment this..

  • @samardebnath6581
    @samardebnath6581 5 ปีที่แล้ว

    Plz explain wordpress codex code for uninstall.php
    Without using OOP

  • @Omeostatica
    @Omeostatica 6 ปีที่แล้ว +1

    Why do you use $wpdb when there are high level functions avaiable? We can use SQL with PDO or mysqli :), come on just jokes, great jobs!!!

    • @alecaddd
      @alecaddd  6 ปีที่แล้ว +1

      It's just an example, you can use what you want for these methods :D

    • @Omeostatica
      @Omeostatica ปีที่แล้ว

      @@alecaddd You should write the query in general purpose:" DELETE FROM ${$wpdb->prefix}posts WHERE..."

  • @aimanhujazi
    @aimanhujazi 6 ปีที่แล้ว +5

    Its UN INSTALl not uni stall lol

    • @alecaddd
      @alecaddd  6 ปีที่แล้ว

      Yup, many users pointed it out, my English is garbage :P