WordPress Plugin Development - Part 30 - How to Delete a Custom Post Type

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ม.ค. 2025

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

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

    Noticed and interesting bug. When you add products as a id and have woocommerce installed it will put that CPT in the same place as woocommerce in the panel.

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

      Uh, that's odd...

    • @adhdaddventure
      @adhdaddventure 4 ปีที่แล้ว +2

      @@alecaddd yes I think so too. I did check the database and the data is at the right place. Could it be that the id I identical since Woocommerce have a 'Products' CPT. I will test again and set everything to zero by cleaning the database deactivate and activate the plugin and dump some to see what's cooking

    • @130kilos
      @130kilos 4 ปีที่แล้ว

      @@adhdaddventure @Alessandro Castellani : I ran into the same issue, not specifically using the same "product" as new cpt id but simply activating the custom post type manager section of the plugin and/or custom taxonomy (ie: adding subpages) creates a woocommerce admin menu page for the woocommerce "setup wizard"... very weird.. if anyone has an idea what creates such interference with woocommerce, I'd be delighted to know..

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

      I just finally got bug fixed after numerous trials (don't ask me why it only showed up in cohabitation with woocommerce, might very well be a random error due to erratic values of $admin_pages member variable of the SettingsApi class) - here's the solution: on line 70 of Alessandro's github repo for SettingsApi.php, before the add_menu_page function execution, ensure you verify first that it is not an empty array. So ensure you check using this : if(!empty($this->admin_page)) {...}. Because otherwise, when you enable custom post type manager or custom taxonomy manager, their own encapsulated SettingsAPI objects will have their own $admin_subpages variable populated, but NOT their $admin_pages variable. In such cases, running add_menu_page on the next line (ie: line 71 of SettingsApi.php on Alessandro's repo) may lead to erratic results (for me cohabitating with woocommerce, it added a "new" main menus without any menu title but with one subpage each being the woocommerce setup wizard. Happened each time i was executing add_menu_page with an empy admin_pages array, ie: 1 for each manager the cpt and the taxonomy managers.

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

      @@130kilos i will have a look and see if I have everything in order. Thank for the investigation :)

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

    HELLO ALEX.... ANOTHER GREAT VIDEO... ITS REALLY NICE TO HEAR YOUR SWEET VOICE. GREAT INFORMATION AND KNOWLEDGE...🙌🙌🙌

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

      Oh, it's the first time someone says that I have a sweet voice, ahaha, thank you so much

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

      Alessandro Castellani
      Hello alex. I sent you massage and email regarding my website. Just waiting for you reply. Thx

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

    Looking forward for the next one :)

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

      Thanks, next week I should be able to publish 3 more of these.

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

      appreciated

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

    Also, I like to add information to the confirm dialog that shows exactly which record is to be deleted. Just in case the user clicked on the wrong record and did not realize it. So, I would use: confirm("Are you sure you want to delete the ['.$option['singular_name'].'] Post Type?
    WARNING: No Posts associated with this Post Type will be removed.") Note too that the "
    " line feed may be used to separate lines in the dialog window (when it is used inside double quotes).

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

    Thanks for another video
    And Happy holi

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

      Thanks for watching, all the best to you!

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

    Hi,
    I am facing some error 'sections not define' please tell me what I do...

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

    I have never thought of using the WP like that. Didn't know it had all those options. Big up! Nice reuse of code

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

      Thanks, man, I'm glad my tutorials are helpful.
      WordPress can do a lot, but we usually prefer to use plugins or prepackaged themes.

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

      Alessandro Castellani they are an eye opener. The simple things that are reusable. Keep that going

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

    Awesome Alex Sir:D,
    HAPPY HOLI FROM INDIA 😎

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

      Hey man, thank you so much :D
      All the best to you!

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

    Can u make a video on how make a custom post status like publish,draft.

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

      Hi, the feature to add a new post status is still in development: codex.wordpress.org/Function_Reference/register_post_status
      I'll do a tutorial when it gets released.
      Cheers

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

      Okay TQ....ur tutorials are awsome

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

    Great tutorial man. I was just playing with the code and found that, whenever we submit any form on this page, all the settings callback (like cptSanize() ) gets called. Does it triggers all callbacks associated to same 'option_group'?

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

    I'm not sure if it's been asked before, but what configuration do you use to get your php errors and var_dumps to show up structured and organized? I only get a barely intelligible jumbled mess

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

      eh, i figured it out, but it was a huge PITA because xdebug isn't currently available for the 32bit version of php 7.3 that came with my xampp installation. now i get to back up databases and recreate permissions 😒

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

      Yeah, that's a default for the version of PHP I'm using. I didn't know that was a difference between the 32 and 64 bit

  • @SabbirAhmed-cm6hk
    @SabbirAhmed-cm6hk 6 ปีที่แล้ว

    i have facing this error in too much lines:: : Illegal string offset 'post_type' in

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

      How did you jump from video 22 to video 30 in 1hr?

    • @SabbirAhmed-cm6hk
      @SabbirAhmed-cm6hk 6 ปีที่แล้ว

      :D I already tried it thats why I have facing these problem now I again watch tutorial 25. is this okay for me??
      @@alecaddd

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

    Looking forward to reviewing more of your lessons. You've done a very good job on the progressive steps to build a plugin. However, I am skeptical of using a lot of class files, as it becomes similar to loading many CSS or JS files. The end result can be class files calling more class files that eventually impact performance. Plus, I find a lot of OOP overkill when classes are used as a default programming method, and they are not really necessary to achieve similar or better results. I create and use php classes for database table data and CRUD, thereby encapsulating the db data and methods.

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

      Sure, I totally agree with you.
      If I'm not wrong, I think I said it at the beginning of this series.
      This approach of building plugins is just one of many hundreds and what I'm showing here is specifically tailored to learn OOP and Plugin building at the same time. That doesn't mean my methods and approaches are the only correct way, and after finishing this series every developers should update their code and build a plugin the way they want to or the way they feel comfortable.
      I'm the first to admit my code is not perfect and there are a million different ways to do it better :D

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

    1st comment 😊 thanks for great tutorial sir 😊

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

      Thanks for watching and commenting so quickly :D

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

      Bell is On 😁😁

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

      Great, thank you so much :D

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

    Hi Alex master, you teach lot things in WordPress, can you make a page in plugin and create a form with complex fields and create a separate table and save in database with validations because it is the one thing missing from you, can you make in this plugin or separate plugin, because for it will take just 20 minutes for this tutorial, it's my request can you make it

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

      It's already part of this series. Keep watching and you'll learn how to do it :D

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

      Alessandro Castellani yeah it will be treat for us

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

      You asked what I want to ask

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

    Do you know how to recover a deleted custom post type?

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

    I am facing this error:
    Are you sure you want to do this?
    Please try again.

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

      the issue is solved. BTW you are awesome Alex Sir

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

      Cheers

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

    I would not call globals ($_GET & $_POST) directly, but use the php filter_input functions, like this: $remove = filter_input( INPUT_POST, 'remove', FILTER_SANITIZE_STRING, array( 'default' => false ) ); Setting the default option will return false if the field does not exist, or if it is empty, otherwise NULL or False will be returned respectively, which would require 2 checks afterwards. Check for a valid value: if ( $remove ), then unset ( $output[$remove] ). Safer way to handle global input data. There are also the WP functions, such as sanitize_text_field(), but may not be the best solution for simple, raw input data from a custom form that is not being inserted into a WP table, the way it is used here.

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

      Thanks for the info

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

    $rate=>giveHimFiveStars(true);

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

    why is it so fn hard to delete? lol. What a joke.