I don’t understand why use array inside the add action hook to create custom post type using object oriented way

Question

<?php
/*
Plugin Name: My Plugin
Plugin URI: https://my.plugin.com
Description: My plugin description
Version: 1.0.0
Author: Me
Author URI: https://my.website.com
License: GPL2 (or whatever)
*/

class myClass {

    function __construct() {

        add_action( 'init', array( $this, 'create_post_type' ) );

    }
    function create_post_type() {
    $name="Foos";
        $singular_name="Foo";
        register_post_type( 
            $name ,
            array(
                'labels' => array(
                    'name'               => _x( $name, 'post type general name' ),
                    'singular_name'      => _x( $singular_name, 'post type singular name'),
                    'menu_name'          => _x( $name, 'admin menu' ),
                    'name_admin_bar'     => _x( $singular_name, 'add new on admin bar' ),
                    'add_new'            => _x( 'Add New', strtolower( $name ) ),
                    'add_new_item'       => __( 'Add New ' . $singular_name ),
                    'new_item'           => __( 'New ' . $singular_name ),
                    'edit_item'          => __( 'Edit ' . $singular_name ),
                    'view_item'          => __( 'View ' . $singular_name ),
                    'all_items'          => __( 'All ' . $name ),
                    'search_items'       => __( 'Search ' . $name ),
                    'parent_item_colon'  => __( 'Parent :' . $name ),
                    'not_found'          => __( 'No ' . strtolower( $name ) . ' found.'),
                    'not_found_in_trash' => __( 'No ' . strtolower( $name ) . ' found in Trash.' )
                ),
                'public'             => true,
                'has_archive'        => strtolower($taxonomy_name),
                'hierarchical'       => false,
                'rewrite'            => array( 'slug' => $name ),
                'menu_icon'          => 'dashicons-carrot'
            )
        );

    }

}
$my_class = new myClass();
?>

0
Buttered_Toast 3 months 2022-05-29T03:59:44-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse