Since I saw a couple videos of this series what I was trying to do with the last videos, is first take a look at the GitHub repository, see if I understand, try to do it and then watch the video. Amazing learning experience!
Like always. awesome tutorial... One slight confusion : with this statement, $this->settings->addPages( $this->pages )->withSubPage( 'Dashboard' )->register(); Shouldn't there be Dashboard sub-page , even though we removed all other sub-pages?
Mh, I don't remember this particular section as I recorded it a while ago, but yes, if the menu doesn't have any subpage, you can remove the withSubpage() method.
The repository shows the wrong code in CustomPostTypeController the code above the activated if statement is missing and that code in the if statement is wrong. Try using. if ( ! get_option('tacruc_plugin')['cpt_manager'] ) return;
Hello sir!! Thanks for giving awesome tutorials for Plugin development. I'm facing a problem. Actually I'm trying to develop a plugin with your instructions. I'm using an 8.2.13 version of PHP and getting a Deprecated notice. Can you please help me to solve this issue?
@@alecaddd Alessandro, Thanks for replying so quickly. I was curious what's formatting the php operators into arrows in Sublime Text? Here's are two example's of php operators that i'm referring too (=>), ($this->). It makes the code so much easier to read. Thanks for your time.
I followed a slightly different path. I wrote an initializer class which injects the constants and call register on the service classes. I registered the basics like activate, deactivate, uninstall, admin pages, etc. in the beginning. After that in the admin pages I call the initializer again with each menu point, so I was able to initialize the CPTs by adding the CPT Manager menu point. I start to like my code and this tutorial... 🙂 if ($mainOptions['cpt_manager']){ Initializer::registerService(\Castellani1\Base\BookPostType::class); $this->settings->withSubPage([ 'page_title' => 'Castellani CPT Manager', 'menu_title' => 'CPT Manager', 'capability' => 'manage_options', 'menu_slug' => 'cpt_manager', 'renderer' => function (string $pageId, array $page, SettingsApi $settings){ echo 'something'; } ]); }
Hi, Alessandro. you forgot to add this code on lesson 24 on your git repository: $option = get_option('alecaddd_plugin'); $activated = isset($option['cpt_manager']) ? $option['cpt_manager'] : false;
Mh, I'm not sure I understand the question. Do you want to integrate the code into your theme to not use it as a plugin? If that's the question, yes, you can do it.
Hi Alex! I make a plugin for your lessons, it works fine on the localhost, but as soon as I transfer the plugin to the web server (hosting) it does not work (the menu does not appear). I tried to check "var_dump(class_exists('Inc\\Init'));" and get "bool(false)".
I have started to build another plugin based on what I have learned here so far. Developing locally right now using MAMP. When I activate my new plugin, it appears to be calling methods from my existing plugin from this tutorial, i.e. my Alecaddd plugin ends up with two "Settings" links and two entries in the WordPress menu, with sub-pages. This doesn't appear to happen the other way, that is, my Alecaddd plugin being activated doesn't have the same effect on my new plugin. There doesn't appear to be any references in my new plugin to my tutorial plugin. Doesn't appear to have anything with Composer namespacing either. Any ideas?
Mhhh, I'm not sure I understand your issue. Do you have a different namespace for your composer autoload? Try to run `composer dumb-autoload` in your terminal in the root directory of your new plugin. I'm not even sure if that could be an issue related to MAMP
I changed the name of my autoload namespace from "Inc" to "Foo" and it worked. My new plugin no longer appears to be accessing the method in the tutorial plugin. I assumed that the two namespaces would be separate, though, since they were mapped to directories with different names. I would also assume that this wouldn't happen even if the namespaces and directories were named identically since they are in different plugin directories with separate instances of composer.json, etc. Thinking this is perhaps a MAMP issue? Thanks again, Alex!
Questa è una cosa random che qualche volta confonde anche me. Con composer autoload sembra non importi se il nome del file è maiuscolo o minuscolo, ma solo se la classe abbia lo stesso identico nome del file.
My bad. Not enough OOP experience. I am originally a C and Fortran guy. Question : Since all the classes have the register() method, in a call-chain such as $this->settings->addPages($this->pages)->withSubPage( 'Dashboard' )->register(); or $this->settings->addSubpages($this->subpages)->register(); How do we know, which register() method is being called (i.e. which class this register method will come from ?). Many times this register() call is within the register() function. It looks like calculating a factorial with recursion. But definitely it is not.
PHP handles these methods in a linear way and the chaining always refers to the starting point. So, in this case, we're starting the $this->settings, which refers to the settings variable assigned in $this class instance. The settings variable is holding a new instance of the SettingsApi() class, so, all the methods that you're calling in the chain, are methods that belong to the SettingsApi(). The final register() method, also belongs to the SettingsApi() class. I hope that helps understanding a bit more how PHP handles these stuff. Cheers
If you look at the code in the class SettingsApi located in {your-plugin}/inc/Api/SettingsApi.php. The methods addPages(), withSubPages(), and addSubPages return the instance itself "this" which it points to the class SettingsApi. So the $this->settings really is an instance of the SettingsApi.
Hi, I have checked and think that it would be more simple in the end, instead of: $option = get_option('alecaddd_plugin'); $activated = isset($option['cpt_manager'])? $option['cpt_manager'] : false; if(!$activated) return; to just use: $option = get_option('alecaddd_plugin'); if(!$option['cpt_manager']) return; No use of isset and all that, worked in my case... Cheers,
i used a method like public function blablabla() { $this->pages = $this->helper->setPages($this->callbacks) } ,,helper,, become a class and im gonna put there all functionalities to keep controllers very clean what do you think about this? i think i said this in all my commets but thanks for you r help helper file it s gonna be a mess but with some comments it will be right...i think xD
Mh, that's not a great approach. You shouldn't pack all your methods inside one single class. If you do that, you're basically discarding the benefits of object oriented programming and you simply have procedural code wrapped in a class. With the code structure I created, your methods should be written in the Controller and each class should have the methods related to that specific section. Small files with dedicated targeted code for a scalable and maintainable code base.
I see !activated not logic from PHP I mean if activated is true meaning not true will back false and if activated is false meaning not false will back false I see this logic I do not know sorry for my bad English
Since I saw a couple videos of this series what I was trying to do with the last videos, is first take a look at the GitHub repository, see if I understand, try to do it and then watch the video.
Amazing learning experience!
Cool, thanks!
Really friendly to made those tutorials thanks a lot man.
Great video. Have you ever done any work with building a hipaa compliant application? I am working on one now and could use some advice.
No, I'm sorry, never worked with something like that.
You are genius.Thanks very much Alessandro.
Ah, thank you so much :D
Like always. awesome tutorial...
One slight confusion : with this statement, $this->settings->addPages( $this->pages )->withSubPage( 'Dashboard' )->register();
Shouldn't there be Dashboard sub-page , even though we removed all other sub-pages?
Mh, I don't remember this particular section as I recorded it a while ago, but yes, if the menu doesn't have any subpage, you can remove the withSubpage() method.
The repository shows the wrong code in CustomPostTypeController the code above the activated if statement is missing and that code in the if statement is wrong.
Try using.
if ( ! get_option('tacruc_plugin')['cpt_manager'] ) return;
oops, sorry for the mistake.
Sometimes I mess things up when updating the repo.
Thanks for the heads up
Thanks, men it works for me!
I think we can create new method in ManagerCallbacks class to make it simple when check the active manager.
That could be an approach, go for it and will see if I decided to do something similar in the next video :D
Hello sir!!
Thanks for giving awesome tutorials for Plugin development.
I'm facing a problem. Actually I'm trying to develop a plugin with your instructions. I'm using an 8.2.13 version of PHP and getting a Deprecated notice. Can you please help me to solve this issue?
Great tutorial. I was wondering what packages are you using in your code editor?
A simple wordpress hooks and autocomplete for Sublime Text
@@alecaddd Alessandro, Thanks for replying so quickly. I was curious what's formatting the php operators into arrows in Sublime Text? Here's are two example's of php operators that i'm referring too (=>), ($this->). It makes the code so much easier to read. Thanks for your time.
That's my font that comes with font-ligatures feature. The font is called Fira Code.
I followed a slightly different path. I wrote an initializer class which injects the constants and call register on the service classes. I registered the basics like activate, deactivate, uninstall, admin pages, etc. in the beginning. After that in the admin pages I call the initializer again with each menu point, so I was able to initialize the CPTs by adding the CPT Manager menu point. I start to like my code and this tutorial... 🙂
if ($mainOptions['cpt_manager']){
Initializer::registerService(\Castellani1\Base\BookPostType::class);
$this->settings->withSubPage([
'page_title' => 'Castellani CPT Manager',
'menu_title' => 'CPT Manager',
'capability' => 'manage_options',
'menu_slug' => 'cpt_manager',
'renderer' => function (string $pageId, array $page, SettingsApi $settings){
echo 'something';
}
]);
}
Great tutorial
Hi, Alessandro. you forgot to add this code on lesson 24 on your git repository: $option = get_option('alecaddd_plugin');
$activated = isset($option['cpt_manager']) ? $option['cpt_manager'] : false;
Oh really? Sorry about that, and thanks for the heads up.
Could the codes for this tutorial be used to create a custom field in other words it would no longer be a plugin but native to the theme...
Mh, I'm not sure I understand the question. Do you want to integrate the code into your theme to not use it as a plugin?
If that's the question, yes, you can do it.
OK thanks....
Hi Alex! I make a plugin for your lessons, it works fine on the localhost, but as soon as I transfer the plugin to the web server (hosting) it does not work (the menu does not appear). I tried to check "var_dump(class_exists('Inc\\Init'));" and get "bool(false)".
Fantasy! I found my mistake! I accidentally named the file Init.php in lowercase (init.php)
Cheers
I have started to build another plugin based on what I have learned here so far. Developing locally right now using MAMP. When I activate my new plugin, it appears to be calling methods from my existing plugin from this tutorial, i.e. my Alecaddd plugin ends up with two "Settings" links and two entries in the WordPress menu, with sub-pages. This doesn't appear to happen the other way, that is, my Alecaddd plugin being activated doesn't have the same effect on my new plugin. There doesn't appear to be any references in my new plugin to my tutorial plugin. Doesn't appear to have anything with Composer namespacing either. Any ideas?
Mhhh, I'm not sure I understand your issue.
Do you have a different namespace for your composer autoload?
Try to run `composer dumb-autoload` in your terminal in the root directory of your new plugin.
I'm not even sure if that could be an issue related to MAMP
I changed the name of my autoload namespace from "Inc" to "Foo" and it worked. My new plugin no longer appears to be accessing the method in the tutorial plugin. I assumed that the two namespaces would be separate, though, since they were mapped to directories with different names. I would also assume that this wouldn't happen even if the namespaces and directories were named identically since they are in different plugin directories with separate instances of composer.json, etc. Thinking this is perhaps a MAMP issue?
Thanks again, Alex!
register_post_type()
Post type key. Must not exceed 20 characters.
That's why the custom post type doesn't show.
Uh, really? That's a really strange limitation
Ale, ma il nome dei file non è "case sensitive"? Se rinomino "Admin.php" in "admin.php" il plugin funziona sempre ...
Questa è una cosa random che qualche volta confonde anche me. Con composer autoload sembra non importi se il nome del file è maiuscolo o minuscolo, ma solo se la classe abbia lo stesso identico nome del file.
I get this error: Error: Call to undefined method Inc\Base\CustomPostTypeController::activated()
Check my source code on GitHub if you have issues.
I've really no idea :D
My bad. Not enough OOP experience. I am originally a C and Fortran guy. Question :
Since all the classes have the register() method, in a call-chain such as
$this->settings->addPages($this->pages)->withSubPage( 'Dashboard' )->register(); or
$this->settings->addSubpages($this->subpages)->register();
How do we know, which register() method is being called (i.e. which class this register method will come from ?).
Many times this register() call is within the register() function. It looks like calculating a factorial with recursion. But definitely it is not.
PHP handles these methods in a linear way and the chaining always refers to the starting point.
So, in this case, we're starting the $this->settings, which refers to the settings variable assigned in $this class instance. The settings variable is holding a new instance of the SettingsApi() class, so, all the methods that you're calling in the chain, are methods that belong to the SettingsApi().
The final register() method, also belongs to the SettingsApi() class.
I hope that helps understanding a bit more how PHP handles these stuff. Cheers
If you look at the code in the class SettingsApi located in {your-plugin}/inc/Api/SettingsApi.php. The methods addPages(), withSubPages(), and addSubPages return the instance itself "this" which it points to the class SettingsApi. So the $this->settings really is an instance of the SettingsApi.
Hi,
I have checked and think that it would be more simple in the end, instead of:
$option = get_option('alecaddd_plugin');
$activated = isset($option['cpt_manager'])? $option['cpt_manager'] : false;
if(!$activated)
return;
to just use:
$option = get_option('alecaddd_plugin');
if(!$option['cpt_manager'])
return;
No use of isset and all that, worked in my case... Cheers,
i used a method like
public function blablabla() {
$this->pages = $this->helper->setPages($this->callbacks)
}
,,helper,, become a class and im gonna put there all functionalities to keep controllers very clean
what do you think about this?
i think i said this in all my commets but thanks for you r help
helper file it s gonna be a mess but with some comments it will be right...i think xD
Mh, that's not a great approach.
You shouldn't pack all your methods inside one single class. If you do that, you're basically discarding the benefits of object oriented programming and you simply have procedural code wrapped in a class.
With the code structure I created, your methods should be written in the Controller and each class should have the methods related to that specific section. Small files with dedicated targeted code for a scalable and maintainable code base.
I see !activated not logic from PHP I mean if activated is true meaning not true will back false and if activated is false meaning not false will back false I see this logic I do not know sorry for my bad English