Create a WordPress Plugin from Scratch - Part 4 - Custom Post Type

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

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

  • @JohnLittlefield
    @JohnLittlefield 4 ปีที่แล้ว +121

    One note: While debugging I discovered the root problem to the 'Books' Label not appearing in the left collum. At 5:36 when you fixed/added the 'label' parameter it appears you corrected a syntax error and removed the single quotes around 'true'.
    INCORRECT: register_post_type('book', ['public' => 'true', 'label' =>'Books'] );
    CORRECT: register_post_type('book', ['public' => true, 'label' =>'Books'] );
    Your training video has been a delight on a cold Saturday afternoon. I've always wanted to program a plugin for Wordpress and your video has made the process so approachable. I'm feeling much gratitude in being released from using other plugins to accomplish what I want.

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

      Thank you so much

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

      Thanks John! I wasn't sure why it wasn't working for me. I was searching online and triple checking my syntax trying to determine what was wrong. Then it dawned on me to check the comments of the video and there was your answer. Exactly what I needed. Thanks again

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

      thanks

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

      @@DanielTriesLife thanks to all

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

      Thanks for that one!

  • @markgitau6647
    @markgitau6647 5 ปีที่แล้ว +21

    *Video Summary*
    Review of previous video 0:20
    Start Lesson 0:55
    *Main goal:* Create CPTs and Flush rewrite rules
    What is a Custom Post Type (CPT): Simply put a CPT is a user defined WordPress blogpost
    Unlike ordinary WordPress blogposts, CPTs allow the developer to add his/her own custom fields thus making them more versatile. Good examples of CPTs are products and appointments.
    Flushing rewrite rules is used to reset the WP environment after making major changes that the new settings can be reflected in the WP environment
    *How to generate a CPT **1:50*
    Add a new method to your class that will handle all the user defined code for adding your CPT. In this case we have named it custom_post_type(). In the method make a call to the register_post_type() which as the name suggests will register the new CPT
    The register_post_type() function will take in 2 main arguments
    ->CPT Slug
    ->An array of additional features that further define your CPT e.g. its label etc.
    _function custom_post_type(){_
    _register_post_type(‘post_type_slug’,array());_
    _}_
    *Hook our method to init* 3:00
    We then need to ensure that our new function/method is executed when the plugin is being initialized i.e. when we are instantiating our class, this is done by calling our new function inside the constructor of our class since the constructor is always executed when a class is instantiated
    *Syntax* 4:10
    _function __construct(){_
    _add_action(‘init’, array($this,’function_name’))_
    _}_
    *Actual code*
    _function __construct(){_
    _add_action('init', array($this,'custom_post_type'));_
    _}_
    *refresh the rewrite rule* 6:33
    _flush_rewrite_rules();_
    This can be executed on activate plugin function and the deactivate plugin function

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

      what if we dont add the flush rewrite rules()

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

      thanks a lot!

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

      your comments should be pinned

  • @eric.slyfield
    @eric.slyfield 3 ปีที่แล้ว +7

    It's amazing! When I first came across this series I had no idea what OOP PHP was or why I would be using it and stopped at part three. Now I'm building a more modular OOP theme and want my custom post type in a plugin and... BAM! This is _exactly_ what I'm looking for! Solid content as always, champ!

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

      Thank you so much, I'm glad my videos are helpful for you

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

    You can’t send classname in a static way, because it is not going to be same instance, so it’ll never be able to read same data, $this means current instance of object/class (I know video author know, but whoever didn’t get it this is the reason) and neither methods are defined as static. This video was autoplayed and decided to watch, I like how explain it, great job.

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

    thank you.
    You are the Master of Wordpress developer.

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

    9:25 This method will trigger a fatal error in PHP 7.4, the recommended version of PHP that the current version of WordPress (5.6) is using. If you haven't run into this issue yet, you will once you update your version of PHP.
    This function is correct. custom_post_type needs to be called each time the plugin is initiated, not just when activated.
    function __construct() {
    add_action( 'init ', array( $this, 'custom_post_type ') );
    }
    This next function, as written, is what will throw the error:
    function activate() {
    $this->custom_post_type();
    flush_rewrite_rules();
    }
    $this can no longer be used when not in object context. In addition, the action has already been called in the __construct function. This is all that is needed so far:
    function activate() {
    flush_rewrite_rules();
    }
    Many thanks to the uploader for posting these clips. They are appreciated.

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

      I was wondering about that, thanks for the explanation

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

    Very clear tutorial....Is this approach still current?

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

    Hi,
    thx for the great tutorials.. pls grant me a question:
    at minute 9:40 you are calling the method custom_post_type() directly from AlecadddPlugin::activate() and propagading, that the registration of the CPT will now only be done, when the plugin will be activated and the callback function is called.
    But since you left the add_action hook in the constructor of the class nothing really changes, but to call the AlecadddPlugin::custom_post_type() twice.
    Can you pls explain why you are following this approach?

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

      Whoop, yeah, you're right. I forgot about that hook.
      Don't worry too much about it anyway, because these lessons, up until 11 or 12, are made to give a quick overview of OOP, with different approaches and methods. After these videos, we're gonna start building the actual plugin with a proper structure. Cheers

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

    Alessandro, you called 2 times register_post_type(). Both at 'init' and at ACTIVATE. You told that it is because it may not register at wordpress initialization. Did I understand it right? Could you explain it a little more. If registering at wordpress "init" then why register? If it works on "init" then why call again at activation?

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

    OK, suuuuper bit noob mistake. I've been coding for years, but new to WP and PHP... The plugin was just showing as text on the dash board because... I had

  • @kensleylewis
    @kensleylewis 5 หลายเดือนก่อน

    Can you please answer the question to why you are running custom_post_type() in both the constructor and in the activate methods? It just looks like a bad practice.

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

    Firstable, thanks for sharing your knowledge, I truly appreciate it. Aren't we calling the custom_post_type function twice in this example? once while the initiation through the init hook and again through the activation function?

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

      The first 10-11 episodes of the series are just an overview of different methods and how to setup a plugin in OOP. We're gonna start coding the real plugin around video n.12, so yeah, some duplication or other stupid things can happen :D

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

    I did everything exact as you said but the I don't see any custom post type on the left panel WHY?

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

      Same😅😅

    • @tonyrums
      @tonyrums 5 ปีที่แล้ว +3

      @@yanafit376 I had the same issue. For me it was register_post_type('book', ['public' => true, 'label' => 'Books']);. I had single quotes around 'true' and there should not be any as it is a boolean datatype. Hope that helps

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

      @@tonyrums That was a great catch. Books now displays in the left menu. Thank you

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

    Hello! For developer with VS Code, how extension need to install? The "register_...hook" show 'undefined functions'......

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

    In my enveronment show this messege "The plugin generated 23 characters of unexpected output during activation. If you notice "headers already sent" messages, problems with feeds or other issues, try disabling or removing this plugin." how can I do fix this ?

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

    after declaring add_action in constructor and custom_post_type in activate method. I went to my new generated plugin. I click on add new post put the data. after that i went to database to check the data that i have given in that new post form. guess what i did not find the data in post_type column in post table.
    so my question is where is my data in table? as you have describe in this video that should placed in database table.

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

    i have created a cpt but i cannout get the front end to show the contents of the post i have initialized the has_archive argument to true but i cannot seem to show my custom cpt recent posts or my post content to be shown

  • @fengshuienthusiastllc6398
    @fengshuienthusiastllc6398 6 ปีที่แล้ว +11

    I cant believe I made a plugin that works. Fantastic tutorial! Thanks so much.

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

      Good stuff, isn't building something from scratch amazing? Keep going and Happy Coding!

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

    I was able to Activate/Deactivate plugin but the custom post type will not display in the left hand side of the admin menu.

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

      i think you must call the class
      if(class_exists('AlecadddPlugin'))
      {
      $alecadddalugin= new AlecadddPlugin();
      }

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

      While debugging I discovered the root problem to the 'Books' Label not appearing in the left collum. At 5:36 when he fixed/added the 'label' parameter it appears he corrected a syntax error and removed the single quotes around 'true'.
      INCORRECT: register_post_type('book', ['public' => 'true', 'label' =>'Books'] );
      CORRECT: register_post_type('book', ['public' => true, 'label' =>'Books'] );

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

      @@JohnLittlefield I did that but still the same

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

    I want to ask if the custom post type is created twice with examples you used.
    i.e
    1. first time the constructor is called during the instantiation of the class?
    2. during the activation of the plugin
    class AlecaddPlugin
    {
    public function __construct(){
    add_action( 'init',[$this,'custom_post_type']);
    }
    public function activate(){
    $this->custom_post_type();
    flush_rewrite_rules();
    }
    //...
    public function custom_post_type(){
    register_post_type( 'book', ['label' => 'Books','public' => true] );
    }
    }
    if(class_exists('AlecaddPlugin')):
    $alecaddPlugin = new AlecaddPlugin();
    endif;
    //activation
    register_activation_hook( __FILE__ , array($alecaddPlugin, 'activate'));

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

      In this case yes, but WordPress doesn't create 2 post types, simply overrides the old one. Anyway, keep watching the series as these initial videos are just examples tho show some methodologies and different approaches. We won't keep this code

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

    Hello, I'm trying to follow your tutos to create a simple plugin,but so far I haven't been able to achieve what I want, I'm trying to connect the front of my site with my plugin.
    Basically I have a button on the page and I'm trying to make that when you click it a simple function in the plugin is called, but so far It hasn't worked, do you have any resources that I could consult?
    THX

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

    function custom_post_type() {
    register_post_type('book', ['public'=>true, 'label'=>'Books']);
    }
    function __construct() {
    add_action('init', array($this, 'custom-post-type'));
    }
    CPT doesnt appear to the left, anyone know why? Been trying to fix this for a week now, but can't wrap my head as to why it doesnt, does it affect the coding that I am using a webhotel?

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

    how did you access the database at 10:19? Is it a special software you have to download? I've looked around and they direct towards cpannel, but I unfortunately don't have that

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

      That's called Sequel Pro, it's MacOS SQL client to access local and remote DBs.
      There are various alternatives for Windows and Linux, or even online, like PhpMyAdmin.

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

    Ciao Alessandro.
    grazie per il tuo lavoro.
    Does Wordpress delete the custom post type information in the database once the plugin is deleted/uninstalled as default?
    Thanks

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

    how can we create new file for our CTP .. like single-books.php archive-books.php etc

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

    Alessandro sigue así hermano, es de lo mejor que he visto hasta ahora en TH-cam!

  • @nameless-heart
    @nameless-heart ปีที่แล้ว

    why did you use both $this->create_custom_post_type(); --> in activate function and add_action('init',[$this, 'create_custom_post_type']); --> in construct function

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

    This question is kind of off topic. There is this cool plugin which is made for the admin dashboard only. Do you know what kind of hook I can use to make the plugin appear for all users/public. As in add the plugin to the menu for all to see and access.

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

      I did everything you asked in future videos. Keep watching the series and you'll learn everything you need.

  • @Îmi_plac_Rațele
    @Îmi_plac_Rațele 7 ปีที่แล้ว +1

    Another great job by Alessandro Castellani. A million thanks for you... greetings from Romania

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

      Thank you so much :D

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

    Hi Alessandro, can I make this way custom_product_type ?

  • @ExpoArtFrames-o6o
    @ExpoArtFrames-o6o ปีที่แล้ว

    Your GitHub Last Class Don't activate in WordPress Plugins. I like to follow it with the code writing fist too see if it works.

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

    Hello Alex, I have a question. When I use register_post_type ('book', array('lable' => 'Books', 'public' => 'true')), it seems not be working over here. However, when I assign the array to $args, and use register_post_type('book', $args), it works well. So what is the different?

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

      Interesting. That shouldn't be any different.
      Maybe it's related to your version of PHP. Do you know which version are you running?

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

      register_post_type ('book', array('lable' => 'Books', 'public' => true)) true without ' '

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

      great answer @Matthias Santschi! Indeed, true should be passed without quotes. Tested on PHP v7.2 and Wordpress v4.9.5

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

      @@theGoldenification Thank You :D I was wondering why Books Wasn't Showing Up. Looking through the comments seemed to work

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

    Great video. What editor are you using, and how does it autocomplete for all the WP functions?

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

      VSCode which have extensions helping autocomplete related to PHP and WP

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

    I do not get it cause at the end we code 2 times the activation of posttype... one in constructor the other one is on activation ? so we are making a double CaLL ?

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

    My man, you are the best for this series.

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

      Thank you so much :D

  • @CJ-pd7xg
    @CJ-pd7xg 6 ปีที่แล้ว

    Alessandro, what function would someone use if the plugin they are creating was for accessing the files in the media library? I'm trying to create a visual effect on the thumbnails.

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

      I created a custom widget the access the media library in this series. Keep watching and you'll learn everything you need :D

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

    Hey Alessandro... I m learning with your tutorial. But this tutorial can't work in my case... the Book (Custom_post_type) do not show in my dashboard. How can I resolve this. Or how can I check the error. please help me.

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

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

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

    Hy sir my plugin was not working

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

    This is great tutorial indeed, I rarely found a youtube videos creating plugin tutorial with OOP approach. Hope you can make a tutorial videos on how to create an extension/plugin for woocommerce using OOP. I hardly found on youtube a video like that. Anyway, this videos is what i'm looking for, Thank you very much.

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

    Very good tutorial. I liked and subscribed. Thank you so much.!!

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

      Welcome :D

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

    I thought that $this refers to the object instantiated by the class, but the presenter says that it refers to the class. Please help me understand. Thanks

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

      The official statement says that "it's a reference to the current object", and since the object it's the class, it's a reference of the class. Different ways to say the same thing :D

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

    Hi Sir,
    I have created the simple plugin using your part 2 & part 3 video and while clicking of the Activate button getting the below error.
    "Plugin could not be activated because it triggered a fatal error.
    "
    Even enabled the debug mode getting the same error even after increase the memory limit.
    Can you please help me on this.

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

    Hi I did exactly the same, However I dont see the "Books" post, do you know why ??

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

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

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

    This is confusing.. You put the register post type function inside the constructor. Does'nt this calls this function every time its instantiated , regardless of activation/deactivation?

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

    Was it necessary to call the custom_post_type() function in both places, or is one preferable?

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

      Awesome tutorial, BTW, very thorough. Looking forward to learning more and watching your series on the custom theme with settings.

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

    Are you sure that we need to call this->custom_post_type() inside 'activate' method?
    Each time we activate our plugin we get a redirection to a new page, which means that our plugin will be executed and custom_post_type() will be called on 'init' hook.
    So, your advice doesn't make sense.

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

      This is just an example of how you can achieve something, it's not the golden standard, and if you think there's a better approach, go for it.
      Anyway, until episode 12, these videos are just for introduction and generic overview of how WordPress manages plugins. The real structure and actual plugin will be build later.

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

    Hey!
    Great Series! Super happy to learn this :) But when i try to create the custom_post_type it wont create it, and i can see the code on the top in wp. The showin code starts from when we set the public => true. Any clue? :)

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

      He changes the type of public from a string to boolean during a camera cut around 5:45. He changed 'public'->'true' to 'public'=>true by removing the single quotes. He doesn't mention this in the video. If you go forward a bit, you'll see he made the correction at some point.

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

      @@suntank6 thanks!

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

    Thanks!! awesome video to take my skills to the next level. Great work Alessandro. Ringraziamenti!!

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

    good job Alessandro, can you share the code because i write the same code but nothing new when activating the plugin, and i get an 2834 error note in plugins page.

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

      There you go: github.com/Alecaddd/WordPressPlugin101

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

    I didnt watched whole video but have question. There are deact act unins methods. What's they function ? When we are deactivating or activating plugin they are already doing by wordpress itself am i wrong ? (when we deactivating or uninstalling this plugin CPT already deleting by wordpress)

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

      You should watch the video where I explain why these hooks are useful for a developer.
      Cheers

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

      Thank you so much!

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

    complimenti per la splendida serie di tutorial, personalmente ho un problema con la visualizzazione del cpt, che non mi compare nel backend nonostante abbia ricontrollato piu volte il tuo listato e ricopiato in maniera pedissequa, non visualizzo errori ne il custom post type, magari è cambiata la sintassi con le nuove versioni di wp? utilizzo wp 5.9 installato in locale con wplocal, qualche suggerimento... Grazie in anticipo
    congratulations for the wonderful series of tutorials, personally I have a problem with the display of the cpt, which does not appear in the backend despite having rechecked several times your listing and copied slavishly, I do not see errors nor the custom post type, maybe the syntax has changed with the new versions of wp? I use wp 5.9 installed locally with wplocal, any suggestions ... Thanks in advance

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

    what if i want to create 2-3 custom post or more then that, do i have create and write that all code again and again repeatedly????

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

      You have to write just the code related to the CPT, not the entire plugin.

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

    i have an error even i have exactly same code written as your tutorial , i have error saying when i activate the plug in
    Plugin could not be activated because it triggered a fatal error.
    could you please advise ?

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

      Did you check my source code on GitHub?

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

    What IDE is that?

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

    These videos have got me hooked. New subscriber :)

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

      Thank you so much :D

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

    Is there anything changed on WordPress now? because your tutorial is fine, but register_post_type( 'Book', ['public'=>true] ); Here the book is not showing when I activate the plugin. Instead of that another custom post is created which is also named "posts" , In easy words this is creating a new custom post with the default name "posts"

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

      oops okay. Thank you very much for your response buddy. Have a very nice day :)

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

    Hi Alessandro,
    On the same note of custom post type, I added metaboxes with rating and want to allow comments on the post type. So I want to make the site allow users to comment(review) and edit via front end without accessing the dashboard.
    In case it is too much for a tutorial, can you explain how to make that happen?

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

      We will tackle pretty much all the features you need in this plugin series. On Episode 14 I wrote down everything I'm planning to do.
      Cheers

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

    Do you can create github repository of this lessons? Thanks for your videos!

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

      It's already up on my Github profile, I need to push the code for this lesson, will do later this evening

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

    if(class_exists('Alecadddplugin')){ : Only works here when plugin is activated. shouldn't this condition be true as far as class Alecadddplugin is defined? regardless of Plugin Activated / Deactivated. Can anyone please explain this to me?

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

    no words..your explanation... perfect..

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

      Thank you so much :D

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

    Greate tutorials but I did not get it "Books" on Wordpres dashboard?! I check everything twice.

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

      Check my source code on Github to see if you have any typo.

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

      Tnx, now work, awsome!

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

    Alessandro, is it good or bad using SINGLETON structure instead of creating everytime new object: $alacadddPlugin=new AlacadddPlugin() - lines 61,62 ?

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

      Nor good or bad, it all depends on what you want to use and how you want to. I find Singletons a bit limiting and somewhat complicated, but nonetheless are super helpful if you want to avoid unwanted mutations and keeping some logic under a class that can't be init more than once.

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

    Thank you man

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

      You're welcome!

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

    What's the difference between $this->method() and array($this, 'method')

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

      when you write $this inside a class you a referring to the current instance of the class, when you write $this->method(), you are calling the method on the class instance and returns the result. If in this case your method doesn't return anything (what's known as a void method) then you would actually be passing null to the add action argument.
      however when you pass and array and say $this as one argument, you a passing the instance fo the class as the first argument and then a string which is the name of the method as the second argument.
      So in short you want to tell the add_action method the name of the method it should call, you don't actually want to call it yourself.

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

    Thank you Alessandro!

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

      You're very welcome

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

    Thank you Alessandro....

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

      You're very welcome

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

    Thanks Alessandro, that's really helpful. Really appreciate it.

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

      You're very welcome :D

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

    Thank you very much for your information, it is very useful and clear, you give very valuable information !!

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

      Ah, thank you so much for this lovely comment

  • @ahmedraza-hk4hn
    @ahmedraza-hk4hn 5 ปีที่แล้ว

    When created the function of custom post type and adding the action, it is giving this error, and thats why the label books is not showing in side bar:
    Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'ahmedplugin' does not have a method 'custom_post_type' in C:\xampp\htdocs\plugintutorial\wordpress-5.2\wordpress\wp-includes\class-wp-hook.php on line 286

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

      Check my source code on GitHub if something doesn't work

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

    again - great tutorial:)

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

    Can't wait for the next lesson!

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

      Thanks for watching

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

    please if the book post didn't appear for you maybe you should use this method it worked for me class TestPlugin
    {
    function __construct() {
    add_action('init', 'custom_post_type');
    }
    function activate() {
    //flush rewrite rules
    flush_rewrite_rules();
    }
    function deacivate() {
    }
    function uninstall() {
    }
    function custom_post_type() {
    register_post_type( 'book', ['Public' => true, 'label' => 'books'] );
    }
    }

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

      Your code is wrong. I showed in the tutorial that you need to pass the array with the instance of the class in the add_action() method. Also, 'public' should be written lowercase.

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

    First of all, I wanna thank you for all your videos, I have learned (And i'm still learning) a lot about wordpress thanks to you.
    I looked for the function "flush_rewrite_rules" in codex and I found that it takes an expensive operation so it should only be used when absolutely necessary (codex)
    My question is : Should we do the same thing that we have in the example in this link : codex.wordpress.org/Function_Reference/flush_rewrite_rules
    I mean, create a function that register the CPT and flush rewrite rules then call it in deactivation and activation
    Is it OK to call the registation of CPT in deactivation ?
    I Hope my question is clear, and sorry for my english.

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

      Hi, thank you so much for watching my videos.
      Yes, the flush_rewrite_rules() should be used carefully. If you keep following my videos, you'll see that I actually transfer it from the simple activation of the plugin to only being used when creating or deleting a custom post type from within the plugin.
      You don't need to call again the registration of the CPT on deactivation, just have the flush_rewrite_rules() there to deal with it.
      Cheers

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

    thank you very much - i love it. 'It would be a great pleasure if you create more vids.
    you have helped me alot.
    if you come up with more vids - you probably would attract many many ppl - wordpress user and fans from all over the globe

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

    super crisp and clear tutorial ;-)

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

    Thanks for the videos, it helps a lot, but when using OOP the methods (functions) in the class shouldn't have the accessor keyword (public/private) it will be more correct.

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

      It's not required if all your methods are public, but yeah, definitely it's good to have it for better readability

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

    I'm truly surprised to see there are 2 thumbs down on this video ... this baffles me! What kind of people would thumbs down this kinda awesome training ... my guess, they must be mentally challenged! In that case, my apologies ...

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

      It's impossible to please everyone, someone will always dislike you, no matter what :D

    • @b.m.rafiulalam2020
      @b.m.rafiulalam2020 5 ปีที่แล้ว

      @@alecaddd Some people don't know what is the meaning of like/dislike :D Ignore please :)

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

    Awesome...Classes and methods. OOP. I like it. Still on track. Great stuff. Thanks

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

      Thinks are starting to get modular :D

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

    Thank you Sir

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

      You're welcome

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

    AMAZING

  • @md.abulkalamazad4965
    @md.abulkalamazad4965 6 ปีที่แล้ว +1

    confused in flush rewrite rules

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

      What's confusing?

    • @md.abulkalamazad4965
      @md.abulkalamazad4965 6 ปีที่แล้ว

      what does it do?

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

      I said it in the video, exactly at this minute 1:00

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

    Part 1 - 4 done viewing but need to return back later after i'm done with Shopify Mastery!

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

    please provide source code.

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

    awesome videos Its better than Udemmy and Lynda courses very very professional

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

      Oh wow, thank you so much. And most importantly, it's free :P

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

    awesome
    !

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

    continuo a commuovermi

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

      Dai, non fare così, ti giuro che di svarioni linguistici ne faccio in abbondanza

  • @ZaheerAbbas-pn9fx
    @ZaheerAbbas-pn9fx 4 หลายเดือนก่อน

    register_post_type( 'books', ["public" => true, 'label' => 'Books'] );
    Don't add single quote to true, else it is not showing wordpress Version 6.6.1.

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

    source code wii be helpful for us

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

      There's the link to my GitHub repo in the description with full source code.

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

      github.com/Alecaddd/WordPressPlugin101

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

    First I click like and then I watched the video:D
    Sorry for my English:P

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

      Thanks for the trust :D

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

      Your comment summarizes the current political situation in my country.
      Including the apologies x''D

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

      This is what i have been doing, so i don't forget about it!

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

    I'm getting a syntax error warning for the custom_post_type function in Dreamweaver. I'm not getting any warnings or errors when I test it though. Has anyone else had this happen?
    Maybe because it's CS5 they haven't updated their code to include wordpress stuff? or maybe I've just typed something wrong and can't see it haha
    Here's the code, within the class. I've named it ACOrder instead of Books.
    function custom_post_type(){
    register_post_type('acorder', ['public' => true, 'label' => 'ACOrder']);
    }
    Thank you :)

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

      You should switch to a more modern and free code editor like VSCode or Sublime Text

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

      @@alecaddd
      Thank you for all your work! Legend! :)

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

    your videos are dope!! one of the best in the world at learning to be a wordpress developer, as i'm on my way to that!! Thanks a lot for this excellent material dear Master :)
    The only critic is that you don't enlarge your screen enough while you are coding, it is short and not that easy to see when i wish to code live while u do!!
    Pliz could you do a special tuto on how to build a plugin with the kind of dashboard woocommerce has, especially at the level of the Orders or Commands of products: because i wish to know how you can add each product with its quantity, in the same command... i don't know if they do that with jquery or vanillajs... it will be dope you have time for this big challenge for me (Wordpress + jquery or vanillajs)
    May Jesus bless you for your gift :)

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

      Thanks for watching my videos. I thought my resolution was big enough, sorry for the issue, I'll try to increase it a bit more.
      Keep watching the plugin series as I'm building a complex administration area with repeater fields, custom sections, and adavanced options. Cheers

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

      "Keep watching the plugin series as I'm building a complex administration area with repeater fields, custom sections, and adavanced options." "sorry for the issue, I'll try to increase it a bit more."
      Thanks in advance for answering my queries... Cheers man

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

    You should make a plugin tutorial demonstrating the WordPress Http API.
    developer.wordpress.org/plugins/http-api/

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

      Sure, I will, thanks for the suggestion

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

    1/13/2019 => thank you : merci : شكرا : Gracias

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

      You're very welcome :D

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

    Hey, if anyone wants to know a little more about rewrite rules in wordpress, check out this blog post www.pmg.com/blog/a-mostly-complete-guide-to-the-wordpress-rewrite-api/
    More wordpress posts from this site www.pmg.com/blog/tag/wordpress/

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

      Thanks for sharing

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

    Great effort, A lot of appreciations. Thanks

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

    i did that. well nevermind i love your teachings keep the good work, i want to write a plugin about tracking , where i can create a tracking id with map and a short-code to display a tracking form so that when a user enters a tracking id in the front end it will display the tracking details with the location under it.

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

      Keep watching this series and you'll learn everything you need. I tackled the creation of shortcodes, storing dynamic data, and more good stuff. Cheers

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

    5:10 - Deeez

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

    This tutorials must named as "Learning OOP while you Create a WordPress Plugin from Scratch"
    I know OOP.. so I don't need to learn it again!

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

      Skip 3 or 4 videos and you'll be fine

  • @pixel1872
    @pixel1872 10 หลายเดือนก่อน

    ❤🙏

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

    Respect :))

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

      Thanks :D