Plugin Directory

Changeset 3145395


Ignore:
Timestamp:
09/02/2024 01:41:51 PM (18 months ago)
Author:
crazypsycho
Message:

post-type

Location:
dynamictags
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • dynamictags/tags/1.3.0/Lib/DynamicTags/PostType.php

    r3145303 r3145395  
    44
    55use DynamicTags\Lib\ElementBase;
     6use Elementor\Controls_Manager;
    67use Elementor\Core\DynamicTags\Tag;
    78use ElementorPro\Modules\DynamicTags\Module;
     
    1415    use ElementBase;
    1516
    16     public function get_name() {
     17    public function get_name(): string {
    1718        return 'dynamic-tags-post-type';
    1819    }
    1920
    20     public function get_title() {
     21    public function get_title(): string {
    2122        return __( 'Post-Type', 'elementor-pro' );
    2223    }
    2324
    24     public function get_group() {
     25    public function get_group(): string {
    2526        return Module::POST_GROUP;
    2627    }
    2728
    28     public function get_categories() {
     29    public function get_categories(): array {
    2930        return [ Module::TEXT_CATEGORY ];
    3031    }
    3132
    32     public function render() {
     33    protected function register_controls(): void {
     34        $this->add_control(
     35            'format',
     36            [
     37                'label' => __( 'Format', 'dynamic-tags' ),
     38                'type' => Controls_Manager::SELECT,
     39                'label_block' => true,
     40                'default' => 'plain',
     41                'options' => [
     42                    'plain' => 'Plain',
     43                    'singular' => 'Singular',
     44                    'plural' => 'Plural',
     45                ],
     46            ]
     47        );
     48
     49    }
     50
     51    public function render(): void {
    3352        $post = get_post();
    3453
     
    3756        }
    3857
    39         echo $post->post_type;
     58        switch ( $this->get_settings('format')) {
     59            case 'singular':
     60                echo get_post_type_object($post->post_type)->labels->singular_name;
     61                break;
     62            case 'plural':
     63                echo get_post_type_object($post->post_type)->labels->name;
     64                break;
     65            case'plain':
     66            default:
     67                echo $post->post_type;
     68                break;
     69        }
     70    }
     71
     72    public function get_panel_template_setting_key(): string {
     73        return 'format';
    4074    }
    4175}
  • dynamictags/trunk/Lib/DynamicTags/PostType.php

    r2509935 r3145395  
    44
    55use DynamicTags\Lib\ElementBase;
     6use Elementor\Controls_Manager;
    67use Elementor\Core\DynamicTags\Tag;
    78use ElementorPro\Modules\DynamicTags\Module;
     
    1415    use ElementBase;
    1516
    16     public function get_name() {
     17    public function get_name(): string {
    1718        return 'dynamic-tags-post-type';
    1819    }
    1920
    20     public function get_title() {
     21    public function get_title(): string {
    2122        return __( 'Post-Type', 'elementor-pro' );
    2223    }
    2324
    24     public function get_group() {
     25    public function get_group(): string {
    2526        return Module::POST_GROUP;
    2627    }
    2728
    28     public function get_categories() {
     29    public function get_categories(): array {
    2930        return [ Module::TEXT_CATEGORY ];
    3031    }
    3132
    32     public function render() {
     33    protected function register_controls(): void {
     34        $this->add_control(
     35            'format',
     36            [
     37                'label' => __( 'Format', 'dynamic-tags' ),
     38                'type' => Controls_Manager::SELECT,
     39                'label_block' => true,
     40                'default' => 'plain',
     41                'options' => [
     42                    'plain' => 'Plain',
     43                    'singular' => 'Singular',
     44                    'plural' => 'Plural',
     45                ],
     46            ]
     47        );
     48
     49    }
     50
     51    public function render(): void {
    3352        $post = get_post();
    3453
     
    3756        }
    3857
    39         echo $post->post_type;
     58        switch ( $this->get_settings('format')) {
     59            case 'singular':
     60                echo get_post_type_object($post->post_type)->labels->singular_name;
     61                break;
     62            case 'plural':
     63                echo get_post_type_object($post->post_type)->labels->name;
     64                break;
     65            case'plain':
     66            default:
     67                echo $post->post_type;
     68                break;
     69        }
     70    }
     71
     72    public function get_panel_template_setting_key(): string {
     73        return 'format';
    4074    }
    4175}
Note: See TracChangeset for help on using the changeset viewer.