C:\xampp\htdocs\landing\wp-content\updraft\plugins-old\duplicate-post\src\ui\class-admin-bar.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
/**
 * Duplicate Post class to manage the admin bar.
 *
 * @package Duplicate_Post
 */

namespace Yoast\WP\Duplicate_Post\UI;

use 
WP_Post;
use 
Yoast\WP\Duplicate_Post\Permissions_Helper;
use 
Yoast\WP\Duplicate_Post\Utils;

/**
 * Represents the Admin_Bar class.
 */
class Admin_Bar {

    
/**
     * Holds the object to create the action link to duplicate.
     *
     * @var Link_Builder
     */
    
protected $link_builder;

    
/**
     * Holds the permissions helper.
     *
     * @var Permissions_Helper
     */
    
protected $permissions_helper;

    
/**
     * Holds the asset manager.
     *
     * @var Asset_Manager
     */
    
protected $asset_manager;

    
/**
     * Initializes the class.
     *
     * @param Link_Builder       $link_builder       The link builder.
     * @param Permissions_Helper $permissions_helper The permissions helper.
     * @param Asset_Manager      $asset_manager      The asset manager.
     */
    
public function __constructLink_Builder $link_builderPermissions_Helper $permissions_helperAsset_Manager $asset_manager ) {
        
$this->link_builder       $link_builder;
        
$this->permissions_helper $permissions_helper;
        
$this->asset_manager      $asset_manager;
    }

    
/**
     * Adds hooks to integrate with WordPress.
     *
     * @return void
     */
    
public function register_hooks() {
        if ( \
intvalUtils::get_option'duplicate_post_show_link_in''adminbar' ) ) === ) {
            \
add_action'wp_before_admin_bar_render', [ $this'admin_bar_render' ] );
            \
add_action'wp_enqueue_scripts', [ $this'enqueue_styles' ] );
            \
add_action'admin_enqueue_scripts', [ $this'enqueue_styles' ] );
        }
    }

    
/**
     * Shows Rewrite & Republish link in the Toolbar.
     *
     * @global \WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance.
     *
     * @return void
     */
    
public function admin_bar_render() {
        global 
$wp_admin_bar;

        if ( ! \
is_admin_bar_showing() ) {
            return;
        }

        
$post $this->get_current_post();

        if ( ! 
$post ) {
            return;
        }

        
$show_new_draft             = ( \intvalUtils::get_option'duplicate_post_show_link''new_draft' ) ) === );
        
$show_rewrite_and_republish = ( \intvalUtils::get_option'duplicate_post_show_link''rewrite_republish' ) ) === )
                                    && 
$this->permissions_helper->should_rewrite_and_republish_be_allowed$post );

        if ( 
$show_new_draft && $show_rewrite_and_republish ) {
            
$wp_admin_bar->add_menu(
                [
                    
'id'    => 'duplicate-post',
                    
'title' => '<span class="ab-icon"></span><span class="ab-label">' . \__'Duplicate Post''duplicate-post' ) . '</span>',
                    
'href'  => $this->link_builder->build_new_draft_link$post ),
                ]
            );
            
$wp_admin_bar->add_menu(
                [
                    
'id'     => 'new-draft',
                    
'parent' => 'duplicate-post',
                    
'title'  => \__'Copy to a new draft''duplicate-post' ),
                    
'href'   => $this->link_builder->build_new_draft_link$post ),
                ]
            );
            
$wp_admin_bar->add_menu(
                [
                    
'id'     => 'rewrite-republish',
                    
'parent' => 'duplicate-post',
                    
'title'  => \__'Rewrite & Republish''duplicate-post' ),
                    
'href'   => $this->link_builder->build_rewrite_and_republish_link$post ),
                ]
            );
        } else {
            if ( 
$show_new_draft ) {
                
$wp_admin_bar->add_menu(
                    [
                        
'id'     => 'new-draft',
                        
'title'  => '<span class="ab-icon"></span><span class="ab-label">' . \__'Copy to a new draft''duplicate-post' ) . '</span>',
                        
'href'   => $this->link_builder->build_new_draft_link$post ),
                    ]
                );
            }

            if ( 
$show_rewrite_and_republish ) {
                
$wp_admin_bar->add_menu(
                    [
                        
'id'     => 'rewrite-republish',
                        
'title'  => '<span class="ab-icon"></span><span class="ab-label">' . \__'Rewrite & Republish''duplicate-post' ) . '</span>',
                        
'href'   => $this->link_builder->build_rewrite_and_republish_link$post ),
                    ]
                );
            }
        }
    }

    
/**
     * Links stylesheet for Toolbar link.
     *
     * @global \WP_Query $wp_the_query.
     *
     * @return void
     */
    
public function enqueue_styles() {
        if ( ! \
is_admin_bar_showing() ) {
            return;
        }

        
$post $this->get_current_post();

        if ( ! 
$post ) {
            return;
        }

        
$this->asset_manager->enqueue_styles();
    }

    
/**
     * Returns the current post object (both if it's displayed or being edited).
     *
     * @global \WP_Query $wp_the_query
     *
     * @return false|WP_Post The Post object, false if we are not on a post.
     */
    
public function get_current_post() {
        global 
$wp_the_query;

        if ( \
is_admin() ) {
            
$post = \get_post();
        } else {
            
$post $wp_the_query->get_queried_object();
        }

        if ( empty( 
$post ) || ! $post instanceof WP_Post ) {
            return 
false;
        }

        if (
            ( ! 
$this->permissions_helper->is_edit_post_screen() && ! \is_singular$post->post_type ) )
            || ! 
$this->permissions_helper->post_type_has_admin_bar$post->post_type )
        ) {
            return 
false;
        }

        if ( ! 
$this->permissions_helper->should_links_be_displayed$post ) ) {
            return 
false;
        }

        return 
$post;
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586