WordPress Plugin Development - Part 15 - Modular Admin SubPages

Поделиться
HTML-код
  • Опубликовано: 2 дек 2024

Комментарии • 120

  • @ahmedmusawir
    @ahmedmusawir 6 лет назад +20

    This is mind blowing!! Never before anything like this was done on the Net!!! WoW!!! Plz, keep 'em coming ... thx a bunch!!

    • @alecaddd
      @alecaddd  6 лет назад +3

      Ahahaha, I love your excitement, thanks for watching :D

    • @ahmedmusawir
      @ahmedmusawir 6 лет назад +8

      Thanx for the reply! But I'm not kidding ... really, WP and OOP with such clarity?! Nope, you cannot find anywhere else my friend, trust me on this, I'm a youtube junky ... I hope this seriese goes up to 100 episodes!!!

    • @ahmedmusawir
      @ahmedmusawir 6 лет назад +1

      Request: When you make a Vue.js course, plz use WP rest api for the Ajax calls with Axios ... There are a lot of courses out there for Vue.js but nothing that marges WP and Vue together ... special thanx in advance.

  • @sbarmen
    @sbarmen 4 года назад +3

    Just decided to follow these series till the end. Very good learning of both PHP and Wordpress. Love it! I am a novice in programming but love to fiddle with code and technology for my own purposes. Came across this as I have a need to build a plugin for Wordpress and I think I will have much better success if I complete this tutorial before I start with my own code. Thanks for all the efforts you put into the creation of these videos. It is very valuable for me, and many others. Thanks a million!

  • @marciozebedeu
    @marciozebedeu 5 лет назад +3

    You deserve an Oscar for the brilliant work you've done.

  • @rakeshmali1727
    @rakeshmali1727 5 лет назад +1

    Am I the only one who likes the video first and proceed?
    Many, many thanks to you, man!

    • @alecaddd
      @alecaddd  5 лет назад

      But what if the video is actually terrible? :P

    • @rakeshmali1727
      @rakeshmali1727 5 лет назад

      @@alecaddd You're a BRAND, a quality brand.

  • @thesloveniaboy123
    @thesloveniaboy123 6 лет назад +6

    I repeat myself but your tutorials are amazing!

    • @alecaddd
      @alecaddd  6 лет назад

      I'll never get tired of reading this, so, please, keep repeating yourself :P

  • @shaxanematov8516
    @shaxanematov8516 5 лет назад +2

    my english isn't enough to have conversation, but i understood everything that you said. Thank you for amazing video

  • @phil86_
    @phil86_ 3 года назад +1

    Amazing quality as always

  • @tottimophy
    @tottimophy 6 лет назад

    You rock Alessandro, I really appreciate your great work, and I really happy because you really like help people, just amazing. I think that we can improve what you did making more readably as a "Json structure" or something like that. We avoid to create more variables and waste memory, less(null) validations, etc. Is just another way to do it. And again thanks my friend.
    #Admin.php
    $this->pages = array(
    array(
    'page_title' => 'Title',
    'menu_title' => 'Title',
    'capability' => 'manage_options',
    'menu_slug' => 'menu_slug',
    'callback' => function() { echo ':)'; },
    'icon_url' => 'dashicons-store',
    'position' => 56,
    'sub_pages' => array (
    array (
    'page_title' => 'Child title',
    'menu_title' => 'Child titln',
    'menu_slug' => 'can-be-different-slug',
    'callback' => function() { echo ' Hi! '; },
    )
    )
    )
    );
    #SettingsApi.php
    public function addAdminMenu() {
    foreach ( $this->admin_pages as $page ) {
    add_menu_page( $page['page_title'],
    $page['menu_title'],
    $page['capability'],
    $page['menu_slug'],
    $page['callback'],
    $page['icon_url'],
    $page['position']
    );
    foreach ( $page['sub_pages'] as $subpage ) {
    add_submenu_page( $page['menu_slug'],
    $subpage['page_title'],
    $subpage['menu_title'],
    $page['capability'],
    $subpage['menu_slug'],
    $subpage['callback']
    );
    }
    }
    }

    • @alecaddd
      @alecaddd  6 лет назад

      Sure, you can edit the code to better fit your needs.
      Happy Coding!

  • @ScenicRoamer_
    @ScenicRoamer_ 4 года назад +1

    Amazing! These videos improved my plugins development skill.

  • @ChristianTjhai
    @ChristianTjhai 4 года назад +1

    Thanks for the tuts! After I have been watching your videos from 1 to 15 (about 5 hours long), and yet I only see your main concern is to make the code beautiful. I still have not yet get any clue to do CRUD on the admin section. Perhaps it would be a good idea to separate the videos in making it work and making it beautiful. However, I indeed thankful for these videos, and gave thumbs up!

  • @chris07ism
    @chris07ism 6 лет назад +2

    Can't thank you enough! the course is great and it helped me so much to be able to get the source code from github. Thanks again!

  • @FlorinRobertBringTheChill
    @FlorinRobertBringTheChill 3 года назад

    Thanks for your tutorials!

  • @spiralni
    @spiralni 4 года назад

    Great tutorial! Thanks. Instead of using arrays of arrays I would suggest writting a Page class and a SubPage class

  • @therobsonjuliano
    @therobsonjuliano 4 года назад

    You're definetely the best! Thanks for so good content!

  • @prodelpe
    @prodelpe 6 лет назад +1

    Thanks buddy! I've been doing this tutorial and are awesome!!

    • @alecaddd
      @alecaddd  6 лет назад

      Thanks for watching :D

  • @sohanwp
    @sohanwp 3 года назад

    Great tutorial!

  • @MagicMoshroom
    @MagicMoshroom 7 лет назад +2

    You can also write the null check as: *'menu_title' => $title ?? $admin_page['menu_title']*

    • @alecaddd
      @alecaddd  7 лет назад +1

      Oh cool, yeah I forgot about this shorthand, thanks for sharing

    • @thesloveniaboy123
      @thesloveniaboy123 6 лет назад

      Nice shortcut!

  • @andreascott3734
    @andreascott3734 7 лет назад +1

    Hi Alessandro, thanks for your tutorials, i just start started following this plugin tutorial and they are so nice and explanatory but there is something i dont understand yet about plugin development, i saw a tutorial about extending a class called widget, i hope you can make a tutorial about that and create a widget plugin, probably a very simple example...

    • @alecaddd
      @alecaddd  7 лет назад +1

      Yes, I'm gonna build some Widgets in this series and I'll explain how the Widget class of WordPress works and why/how to extend it.
      Cheers

    • @andreascott3734
      @andreascott3734 7 лет назад

      yeah cheers, thanks once again...

  • @sudhakarsudha9655
    @sudhakarsudha9655 7 лет назад +1

    yeah super waiting for next video

    • @alecaddd
      @alecaddd  7 лет назад

      Coming in a couple of days :D

  • @alexdejoncaire
    @alexdejoncaire 6 лет назад +2

    PFF.. I confirm. This is excellent stuff!

  • @duyvu9137
    @duyvu9137 7 лет назад +1

    very very useful, thanks so much Alessandro

    • @alecaddd
      @alecaddd  7 лет назад

      You're very welcome, thanks for watching :D

  • @sevdamurat4455
    @sevdamurat4455 6 лет назад +1

    Keep up good work, thanks

  • @mybluedog24
    @mybluedog24 6 лет назад +2

    For those who has this error "Catchable fatal error: Argument 1 passed to Inc\Api\SettingsApi::withSubPage() must be an instance of Inc\Api\string, string given,", check the accepted answer from here: stackoverflow.com/questions/4103480/how-to-resolve-must-be-an-instance-of-string-string-given-prior-to-php-7 Basically just remove the type check "string", or do the checking inside the function. Hope this helps.

    • @alecaddd
      @alecaddd  6 лет назад

      Thanks for sharing

  • @deephousefridays1911
    @deephousefridays1911 5 лет назад +1

    Oh man you are the wizzard of OZ!

  • @wilsonimport
    @wilsonimport 4 года назад +2

    I know this code is a bit old, I just uploaded the git repository code for this class "Lesson 15" but I can't see the submenus, I also don't see any errors in the console, I'm using Wordpress Version 5.4.1 PHP 7.2

    • @ramonbendeler3947
      @ramonbendeler3947 3 года назад

      Hey I have the same problem, did you already find out wat is was?

    • @lenny99mc
      @lenny99mc 2 года назад

      same here

    • @mathfromzero_
      @mathfromzero_ 7 месяцев назад

      ​@@lenny99mc Do cross check with the git repository codes. I just figure out my code is just missing 's' in capability manage_options which i write manage_option.

  • @nicmicmusic
    @nicmicmusic 6 лет назад +1

    Hi, I have double checked with the gitub repo and my files are the same. I get the error, "Sorry, not allowed to access this page" when I try to get to the sub page. Everything else works. The sub page shows up in the sidebar, but I am not allowed to access it?! Any ideas? Now I'm getting that it cannot load the subpage when I click on it.

    • @alecaddd
      @alecaddd  6 лет назад +1

      Mhh, that's weird. If you copied my code and you're logged in as admin, you shouldn't have issues in accessing the page you created.
      Can you try lowering the required capabilities to something a regular user can access.

    • @nicmicmusic
      @nicmicmusic 6 лет назад +2

      I kept getting 500 internal server error when accessing the subpage. It said "cannot load page". Changing capabilities for subpage didn't work. I fixed it by replacing my wp-includes and wp-admin folders with the latest wordpress install. Must have been some corrupt files or something with the wordpress installation. Weird!
      But it works now.
      Thank for all the great tutorials! :) Have a great day!

    • @alecaddd
      @alecaddd  6 лет назад +1

      Oh wow, that's really strange. Well, I'm glad you solved it and it wasn't my fault :D
      Happy Coding

  • @trongnhanle7658
    @trongnhanle7658 2 года назад

    why you should make a booking appoinment plugin ? . I think it's a cool topic

  • @ruizhu7140
    @ruizhu7140 3 года назад

    It seems that the method "withSubpage" is not required, we can define all the subpages information together in the Admin.php. am I right ? what do you think? Anyway , this is a really amazing tutorials.

  • @musfiquerahaman8975
    @musfiquerahaman8975 3 года назад

    Does 2 class with same name will give an error

  • @sevdamurat4455
    @sevdamurat4455 6 лет назад

    I think there is subtle logic error on "withSubPage" function. Because we create "withSubPage" to create the first tab of Admin MenuS. HOWEVER we might have not one but several admin menus which you already defined admin menu pages as an array. But ""withSubPage" only sub menu for the first page is created. I think it should be modified in a way that it will create first submenus of admin pages not for JUST THE FIRST page but also for the other pages that we want. So to fulfill this we can add an array as second parameter which will take the list admin pages that we want submenus to be added. For example second parameter will be smth. such as [1,0,1,0,0] then we will add sub menu for the first and third admin menu page. No sub menu will be added for the second , forth and fifth admin pages. So on.

    • @alecaddd
      @alecaddd  6 лет назад

      Sure, that's a good point, feel free to update the code as you like or as it fits your needs.

  • @bryceleekelsey
    @bryceleekelsey 6 лет назад +1

    If I add two admin menus with submenus, it only shows "Dashboard" on the top menu. If I changed SettingsApi.php $admin_page = $this->admin_pages[0]; to $admin_page = $this->admin_pages[1]; it would show "Dashboard on the second menu. Is there a way to get this to show "Dashboard on all menus?

    • @alecaddd
      @alecaddd  6 лет назад

      Oh yes, it's a little bug with my structure. I will release an update video soon to tackle this issue. Thanks for the comment.

    • @bryceleekelsey
      @bryceleekelsey 6 лет назад +2

      By the way, your videos are the most educational I have found and the most useful. I've taken classes on Udemy that aren't even close to this. Thanks for providing these tutorials!!!

    • @alecaddd
      @alecaddd  6 лет назад

      You're very welcome, I'm glad my videos are useful for you. Happy Coding :D

    • @RudyGayRaptors
      @RudyGayRaptors 6 лет назад

      Most of the plugins will have only 1 admin menu and 1 dashboard and maybe a few subpages. So even though the design is not flawless but it's useful 99.9% of the time :)

    • @RudyGayRaptors
      @RudyGayRaptors 6 лет назад

      My approach is a little bit different from Alessandro, if I need more than 1 admin menu I'll create 2 different classes in Pages folder (ie. Admin.php and SomeOtherPage.php) because I think that Admin.php should only have 1 main menu, if I need more I'll just add another file inside Pages

  • @peterparkar5313
    @peterparkar5313 4 года назад

    hey there , I wrote my code exactly like you even we can say copy pest . But My output is not give me result like you plezzz reply me it would be very grateful. ..?

  • @jhdteach8301
    @jhdteach8301 5 лет назад

    this error
    Catchable fatal error: Argument 1 passed to Inc\Api\SettingsApi::withSubPage() must be an instance of Inc\Api\string, string given, called in C:\xampp\htdocs\wordpress\wp-content\plugins\alecaddd-plugin\inc\Pages\Admin.php on line 67 and defined in C:\xampp\htdocs\wordpress\wp-content\plugins\alecaddd-plugin\inc\Api\SettingsApi.php on line 27
    how to fix it.

  • @samairali3562
    @samairali3562 4 года назад

    what is the purpose of merging an array ? if you don't merge if you skip merging step still you will get the same end result as you want ... i am getting confused with the merging array concept, i am sure there will be someone else as well .

  • @ghost_4358
    @ghost_4358 5 лет назад

    Hello.. Can you tell me how to create wp_list_table from the callback. I feel confused to create it with your way. But I like your way beacuse it's so good to read and also clean..

  • @sevdamurat4455
    @sevdamurat4455 6 лет назад

    1. I think using 'setPages' instead of 'public function addPages( array $pages )' would have been a better choice because there is nothig incremental, pages completely are set at once. (at SettingsApi.php) 2. Is it a wordpress necessity that parent plugin menu and first plugin SUB-MENU should point to the same page?

    • @alecaddd
      @alecaddd  6 лет назад

      1. Sure, you can change the code however you want.
      2. Yup

  • @sameera-dananjaya-wijerathna
    @sameera-dananjaya-wijerathna 2 года назад

    Why did you define $title in this function - public function withSubPages(string $title = null)

  • @webprogramming2707
    @webprogramming2707 5 лет назад

    Have learnt a lot :)....thank you soooo much

  • @dipakdhakal3008
    @dipakdhakal3008 7 лет назад +1

    thanks you very much it really help me thanks again

    • @alecaddd
      @alecaddd  7 лет назад

      Happy to hear that :D

  • @rutvitrivedi6763
    @rutvitrivedi6763 6 лет назад

    Hi I am following your series it's great and it's all good till now but I cant add submenu somehow n there is no error, can you please help.

    • @alecaddd
      @alecaddd  6 лет назад

      Check my source code on GitHub if you have any issues.

  • @engineser6470
    @engineser6470 6 лет назад

    subpages not working here, no php error and i cannot find the failure i did everthing as in video but not working pages works but subpages not ...

    • @engineser6470
      @engineser6470 6 лет назад

      may it does not work with the wordpress update inkl gutenberg? pages works but subpages not? i checked all files also with yours in github nothing found...

    • @engineser6470
      @engineser6470 6 лет назад +1

      OMG i found the failure :-) it was the parent_slug!! i did not write correct the parent_slug in the subpages

    • @alecaddd
      @alecaddd  6 лет назад

      I'm glad you found the issue

  • @arbnorsalihu700
    @arbnorsalihu700 6 лет назад

    Nice tutorials, I'm following you from the beginning and it is going well, but in this tutorial I have an error: Recoverable fatal error: Object of class Closure could not be converted to string in /home/blabla/public_html/blabla/wp-includes/functions.php on line 1712. Could you please help me about this.

    • @alecaddd
      @alecaddd  6 лет назад

      Check my source code on Github, probably you have a typo somewhere.
      Happy Coding :D

  • @ryanmendoza727
    @ryanmendoza727 6 лет назад

    Hello im stuck please help... TIA
    this code is working, but its not renaming the subpage. its just outputting the [menu_slug].
    $this->settings->addPages( $this->pages )->withSubPage()->addSubPages( $this->subpages )->register();
    and this code is not working. every time im adding the 'Dashboard' my code is not working.
    $this->settings->addPages( $this->pages )->withSubPage('Dashboard')->addSubPages( $this->subpages )->register();
    I got this Error:
    Catchable fatal error: Argument 1 passed to Inc\Api\SettingsApi::withSubPage() must be an instance of Inc\Api\string, string given,

    • @alecaddd
      @alecaddd  6 лет назад

      Check my source code on GitHub to see if you have any typos or mistakes. Cheers

    • @ryanmendoza727
      @ryanmendoza727 6 лет назад

      I got it, Thanks.
      I really love your tutorials.

    • @sheldonesnard4938
      @sheldonesnard4938 6 лет назад

      How did you resolve the error?

    • @ryanmendoza727
      @ryanmendoza727 6 лет назад

      I removed the "string" in $title =null and it works fine.
      I dont know if its ok to do that.

  • @JokesGaloreYT
    @JokesGaloreYT 5 лет назад

    I am getting this error.
    Catchable fatal error: Argument 1 passed to Inc\Api\SettingsApi::withSubPage() must be an instance of Inc\Api\string, string given
    The line causing it is:
    $this->settings->addPages( $this->pages )->withSubPage( 'Dashboard' )->addSubPages( $this->subpages )->register();
    It has a problem with the parameter of withSubPage(). Can anyone help? Alecadd seems to not have this problem and I wrote exactly what he wrote.
    Thanks in advance!

    • @alecaddd
      @alecaddd  5 лет назад

      No need to send me also an email :P
      Did you check my source code on GitHub? Are you sure everything is identical to mine?

    • @JokesGaloreYT
      @JokesGaloreYT 5 лет назад

      Ok. Won't send you again. I just wanted a response quickly.
      But yeah, I did check and everything is identical. But I will check again.
      Thanks.

  • @TMEUCpuntoes
    @TMEUCpuntoes 4 года назад

    Hello im trying to do this video, im following this course from first video and everything is ok... but in this f*** video i was two days stucked... XDDDDD... can you help me please Ale? i do all stuff in that video i review it to check the code and all is fine, my page is working, but no submenu appears in WP desktop... by the way... thank you so much by helping every us with your videos

    • @TMEUCpuntoes
      @TMEUCpuntoes 4 года назад

      im so sorry i found the error... simply i have to put the same capability to page and submenues.... Thanks a lot, you`re the best!!

    • @farringtonworks
      @farringtonworks 3 года назад

      I had the same issue. It turns out, the menu_slug of the admin page, and parent_slug for my submenus didn't match. Once I changed that, everything was fine.

  • @umairriazahmed7075
    @umairriazahmed7075 4 года назад +1

    Awesome but very difficult to understand

    • @maciej__kw
      @maciej__kw 4 года назад

      Yeah, that's just mind blowing. I feel like I'm learning so much, there's a lot happening on these videos, I can't lose focus even for a moment because I will get lost and also lose knowledge

  • @RomySingh420
    @RomySingh420 7 лет назад +1

    nice!

  • @mazenbukhari7101
    @mazenbukhari7101 6 лет назад

    Hello Alex, Thanks for your amazing work.
    I get this error message:
    Catchable fatal error: Argument 1 passed to Inc\Api\SettingsApi::withSubPage() must be an instance of Inc\Api\string, string given, called in C:\wamp\www\website.com\wp-content\plugins\Aim-High-plugin\includes\Pages\Admin.php on line 32 and defined in C:\wamp\www\website.com\wp-content\plugins\Aim-High-plugin\includes\Api\SettingsApi.php on line 20
    line 32: (Admin.php)
    $this->settings->addPages( $this->pages)->withSubPage('Dashboard')->register();
    line 20: (SettingsApi.php)
    public function withSubPage( string $title = null ){
    ps, This is before executing the final step (->addSubPages)

    • @alecaddd
      @alecaddd  6 лет назад

      Mh, that's weird. Did you check my source code on Github to see if you have any issues?
      I wonder if it's a Wamp issue. What version of PHP are you running?

    • @mazenbukhari7101
      @mazenbukhari7101 6 лет назад

      The 5.5.12 version .. i will check the code again and again but if the problem is because of the version tell me please .. many thanks for your help Alessandro

    • @alecaddd
      @alecaddd  6 лет назад

      For these OOP settings, would be recommended to have PHP higher than 5.6
      Version 7 would be the best.

  • @truncus5776
    @truncus5776 5 лет назад +1

    How are you displaying the php errors? my site just crashes???

  • @madalinb7994
    @madalinb7994 6 лет назад

    Warning: strpos() expects parameter 1 to be string, object given in C:\Users\leadsoft\Desktop\xaamp\htdocs\wordpress-4.9.8\wordpress\wp-includes\functions.php on line 5230
    Warning: preg_match() expects parameter 2 to be string, object given in C:\Users\leadsoft\Desktop\xaamp\htdocs\wordpress-4.9.8\wordpress\wp-includes\functions.php on line 5239
    Recoverable fatal error: Object of class Closure could not be converted to string in C:\Users\leadsoft\Desktop\xaamp\htdocs\wordpress-4.9.8\wordpress\wp-includes\functions.php on line 1720
    i dont know what ar those, i try to debug it but all works good, i dont get it

    • @madalinb7994
      @madalinb7994 6 лет назад

      for those how have this error just put $page['parent_slug'] in add_submenu_page, that was the problem, fk it :(

  • @nobir98
    @nobir98 7 лет назад

    Please create a simple plugin using FPDF that create pdf file with client style ( like logo , title in pdf file )
    Thanks :D

    • @alecaddd
      @alecaddd  7 лет назад +2

      Mh, I don't think I'll do that, but I'm sure at the end of this series, you'll have the necessary knowledge to make it yourself :D

    • @nobir98
      @nobir98 7 лет назад +1

      Okay then I will wait for that time .. :D
      Thanks :D

  • @MonirKHAN-hm5wt
    @MonirKHAN-hm5wt 5 лет назад

    You can still get subpages without the method of withSubpage().
    $this->settings->addPages( $this->pages )->addSubPages( $this->subpages)->register();
    If you want to change the default sub-menu title, you should use withSubpage('Whatever title you want' ).
    So I think this method should be named withCustomTitle('Dashboard')
    "Happy Coding " ...

  • @BP-kc3dj
    @BP-kc3dj 6 лет назад +1

    Nice videos. But Please stop showing the wrong way to do things then the right way or the way you want to do it. Just show us the best way from your perspective. Otherwise, its confusing, time consuming and maddening if we are following along then have to change everything. People are busy, with kids or everything else that distracts them on a daily basis. So redoing work already done is problematic for those folks. I am one of them. Again. GREAT VIDEOS otherwise.

    • @alecaddd
      @alecaddd  6 лет назад +6

      Thanks for your comment and for your feedback. I like to teach the way I like to learn, by knowing what I'm doing and why I'm doing it. I think showing common mistakes and bad approaches is important to properly learn to code. I'll try to improve the quality of my videos nonetheless. Cheers

    • @maciej__kw
      @maciej__kw 4 года назад

      @@alecaddd That's in fact slightly irritating, but I think both approaches are good methods. I think the method shown is the harder way of learning but also the most rewarding