| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace FilterEverything\Filter; |
| 5 |
|
| 6 |
if ( ! defined('ABSPATH') ) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
class MetaBoxes |
| 11 |
{ |
| 12 |
public function __construct() |
| 13 |
{ |
| 14 |
add_action( 'admin_head', array( $this, 'adminHead' ) ); |
| 15 |
} |
| 16 |
|
| 17 |
public function adminHead() |
| 18 |
{ |
| 19 |
add_meta_box( |
| 20 |
'filters-set-items', |
| 21 |
esc_html__( "Filters", 'filter-everything' ), // Do not need to escape because of 'trust WordPress' |
| 22 |
array( $this, 'filtersMetabox' ), |
| 23 |
FLRT_FILTERS_SET_POST_TYPE, |
| 24 |
'normal', |
| 25 |
'high' |
| 26 |
); |
| 27 |
|
| 28 |
add_meta_box( |
| 29 |
'filters-set-location', |
| 30 |
esc_html__( "Location", 'filter-everything' ), |
| 31 |
array( $this, 'locationMetabox' ), |
| 32 |
FLRT_FILTERS_SET_POST_TYPE, |
| 33 |
'normal', |
| 34 |
'low' |
| 35 |
); |
| 36 |
|
| 37 |
add_meta_box( |
| 38 |
'filters-set-settings', |
| 39 |
esc_html__( "Settings", 'filter-everything' ), |
| 40 |
array( $this, 'settingsMetabox' ), |
| 41 |
FLRT_FILTERS_SET_POST_TYPE, |
| 42 |
'normal', |
| 43 |
'low' |
| 44 |
); |
| 45 |
|
| 46 |
remove_meta_box( |
| 47 |
'submitdiv', |
| 48 |
array( FLRT_FILTERS_SET_POST_TYPE ), |
| 49 |
'side' |
| 50 |
); |
| 51 |
|
| 52 |
add_meta_box( |
| 53 |
'submitdiv', |
| 54 |
esc_html__( 'Publish', 'filter-everything' ), |
| 55 |
[ 'FilterEverything\Filter\MetaBoxes', 'commonSideMetaBox' ], |
| 56 |
array( FLRT_FILTERS_SET_POST_TYPE ), |
| 57 |
'side' |
| 58 |
); |
| 59 |
|
| 60 |
add_meta_box( |
| 61 |
'filter-set-advice', |
| 62 |
esc_html__( 'How to?', 'filter-everything' ), |
| 63 |
[ 'FilterEverything\Filter\MetaBoxes', 'adviceMetabox' ], |
| 64 |
array( FLRT_FILTERS_SET_POST_TYPE ), |
| 65 |
'side' |
| 66 |
); |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
public static function filtersMetabox( $post, $meta ) |
| 71 |
{ |
| 72 |
$args = array( |
| 73 |
'post' => $post, |
| 74 |
'meta' => $meta |
| 75 |
); |
| 76 |
|
| 77 |
flrt_include_admin_view('filters-set', $args ); |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
public static function settingsMetabox( $post, $meta ){ |
| 82 |
$args = array( |
| 83 |
'post' => $post, |
| 84 |
'meta' => $meta |
| 85 |
); |
| 86 |
|
| 87 |
flrt_include_admin_view('filters-set-settings', $args ); |
| 88 |
} |
| 89 |
|
| 90 |
public static function locationMetabox( $post, $meta ){ |
| 91 |
$args = array( |
| 92 |
'post' => $post, |
| 93 |
'meta' => $meta |
| 94 |
); |
| 95 |
|
| 96 |
flrt_include_admin_view('filters-set-location', $args ); |
| 97 |
} |
| 98 |
|
| 99 |
public static function adviceMetabox( $post, $meta ){ |
| 100 |
$args = array( |
| 101 |
'post' => $post, |
| 102 |
'meta' => $meta |
| 103 |
); |
| 104 |
|
| 105 |
flrt_include_admin_view('filters-set-advices', $args ); |
| 106 |
} |
| 107 |
|
| 108 |
public static function commonSideMetaBox( $post, $args = array() ) { |
| 109 |
global $action; |
| 110 |
|
| 111 |
$post_id = (int) $post->ID; |
| 112 |
$post_type = $post->post_type; |
| 113 |
$post_type_object = get_post_type_object( $post_type ); |
| 114 |
$can_publish = current_user_can( $post_type_object->cap->publish_posts ); |
| 115 |
$filterSet = \FilterEverything\Filter\Container::instance()->getFilterSetService(); |
| 116 |
$under_limit_filter_set = $filterSet->under_limit_filter_set($post_id); |
| 117 |
?> |
| 118 |
<div class="submitbox" id="submitpost"> |
| 119 |
|
| 120 |
<div id="minor-publishing"> |
| 121 |
|
| 122 |
<?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key. ?> |
| 123 |
<div style="display:none;"> |
| 124 |
<?php submit_button( esc_html__( 'Save' ), '', 'save' ); ?> |
| 125 |
</div> |
| 126 |
|
| 127 |
<div id="minor-publishing-actions"> |
| 128 |
<?php |
| 129 |
|
| 130 |
|
| 131 |
/** |
| 132 |
* Fires before the post time/date setting in the Publish meta box. |
| 133 |
* |
| 134 |
* @since 4.4.0 |
| 135 |
* |
| 136 |
* @param WP_Post $post WP_Post object for the current post. |
| 137 |
*/ |
| 138 |
do_action( 'post_submitbox_minor_actions', $post ); |
| 139 |
?> |
| 140 |
<div class="clear"></div> |
| 141 |
</div> |
| 142 |
|
| 143 |
<div id="misc-publishing-actions"> |
| 144 |
<div class="misc-pub-section misc-pub-post-status"> |
| 145 |
<?php esc_html_e( 'Status:' ); ?> |
| 146 |
<span id="post-status-display"> |
| 147 |
<?php |
| 148 |
switch ( $post->post_status ) { |
| 149 |
case 'private': |
| 150 |
esc_html_e( 'Privately Published' ); |
| 151 |
break; |
| 152 |
case 'publish': |
| 153 |
esc_html_e( 'Published' ); |
| 154 |
break; |
| 155 |
case 'future': |
| 156 |
esc_html_e( 'Scheduled' ); |
| 157 |
break; |
| 158 |
case 'pending': |
| 159 |
esc_html_e( 'Pending Review' ); |
| 160 |
break; |
| 161 |
case 'draft': |
| 162 |
case 'auto-draft': |
| 163 |
esc_html_e( 'Draft' ); |
| 164 |
break; |
| 165 |
} |
| 166 |
?> |
| 167 |
</span> |
| 168 |
</div> |
| 169 |
|
| 170 |
<?php |
| 171 |
/* translators: Publish box date string. 1: Date, 2: Time. See https://www.php.net/manual/datetime.format.php */ |
| 172 |
$date_string = esc_html__( '%1$s at %2$s' ); |
| 173 |
/* translators: Publish box date format, see https://www.php.net/manual/datetime.format.php */ |
| 174 |
$date_format = _x( 'M j, Y', 'publish box date format' ); |
| 175 |
/* translators: Publish box time format, see https://www.php.net/manual/datetime.format.php */ |
| 176 |
$time_format = _x( 'H:i', 'publish box time format' ); |
| 177 |
|
| 178 |
if ( 0 !== $post_id ) { |
| 179 |
if ( 'future' === $post->post_status ) { // Scheduled for publishing at a future date. |
| 180 |
/* translators: Post date information. %s: Date on which the post is currently scheduled to be published. */ |
| 181 |
$stamp = esc_html__( 'Scheduled for: %s' ); |
| 182 |
} elseif ( 'publish' === $post->post_status || 'private' === $post->post_status ) { // Already published. |
| 183 |
/* translators: Post date information. %s: Date on which the post was published. */ |
| 184 |
$stamp = esc_html__( 'Published on: %s' ); |
| 185 |
} elseif ( '0000-00-00 00:00:00' === $post->post_date_gmt ) { // Draft, 1 or more saves, no date specified. |
| 186 |
$stamp = wp_kses( __( 'Publish <b>immediately</b>' ), array( 'b' => array() ) ); |
| 187 |
} elseif ( time() < strtotime( $post->post_date_gmt . ' +0000' ) ) { // Draft, 1 or more saves, future date specified. |
| 188 |
/* translators: Post date information. %s: Date on which the post is to be published. */ |
| 189 |
$stamp = esc_html__( 'Schedule for: %s' ); |
| 190 |
} else { // Draft, 1 or more saves, date specified. |
| 191 |
/* translators: Post date information. %s: Date on which the post is to be published. */ |
| 192 |
$stamp = esc_html__( 'Publish on: %s' ); |
| 193 |
} |
| 194 |
$date = sprintf( |
| 195 |
$date_string, |
| 196 |
date_i18n( $date_format, strtotime( $post->post_date ) ), |
| 197 |
date_i18n( $time_format, strtotime( $post->post_date ) ) |
| 198 |
); |
| 199 |
} else { // Draft (no saves, and thus no date specified). |
| 200 |
$stamp = wp_kses( __( 'Publish <b>immediately</b>' ), array( 'b' => array() ) ); |
| 201 |
$date = sprintf( |
| 202 |
$date_string, |
| 203 |
date_i18n( $date_format, strtotime( current_time( 'mysql' ) ) ), |
| 204 |
date_i18n( $time_format, strtotime( current_time( 'mysql' ) ) ) |
| 205 |
); |
| 206 |
} |
| 207 |
|
| 208 |
if ( ! empty( $args['args']['revisions_count'] ) ) : |
| 209 |
?> |
| 210 |
<div class="misc-pub-section misc-pub-revisions"> |
| 211 |
<?php |
| 212 |
/* translators: Post revisions heading. %s: The number of available revisions. */ |
| 213 |
echo wp_kses( |
| 214 |
sprintf( __( 'Revisions: %s' ), '<b>' . number_format_i18n( $args['args']['revisions_count'] ) . '</b>' ), |
| 215 |
array( 'b' => array() ) |
| 216 |
); |
| 217 |
?> |
| 218 |
<a class="hide-if-no-js" href="<?php echo esc_url( get_edit_post_link( $args['args']['revision_id'] ) ); ?>"><span aria-hidden="true"><?php esc_html( _ex( 'Browse', 'revisions' ) ); ?></span> <span class="screen-reader-text"><?php esc_html_e( 'Browse revisions' ); ?></span></a> |
| 219 |
</div> |
| 220 |
<?php |
| 221 |
endif; |
| 222 |
|
| 223 |
if ( $can_publish ) : // Contributors don't get to choose the date of publish. |
| 224 |
?> |
| 225 |
<div class="misc-pub-section curtime misc-pub-curtime"> |
| 226 |
<span id="timestamp"> |
| 227 |
<?php printf( $stamp, '<b>' . $date . '</b>' ); ?> |
| 228 |
</span> |
| 229 |
</div> |
| 230 |
<?php |
| 231 |
endif; |
| 232 |
|
| 233 |
if ( 'draft' === $post->post_status && get_post_meta( $post_id, '_customize_changeset_uuid', true ) ) : |
| 234 |
?> |
| 235 |
<div class="notice notice-info notice-alt inline"> |
| 236 |
<p> |
| 237 |
<?php |
| 238 |
echo wp_kses( |
| 239 |
sprintf( |
| 240 |
/* translators: %s: URL to the Customizer. */ |
| 241 |
__( 'This draft comes from your <a href="%s">unpublished customization changes</a>. You can edit, but there’s no need to publish now. It will be published automatically with those changes.' ), |
| 242 |
esc_url( |
| 243 |
add_query_arg( |
| 244 |
'changeset_uuid', |
| 245 |
rawurlencode( get_post_meta( $post_id, '_customize_changeset_uuid', true ) ), |
| 246 |
admin_url( 'customize.php' ) |
| 247 |
) |
| 248 |
) |
| 249 |
), |
| 250 |
array('a' => array( 'href' => true ) ) |
| 251 |
); |
| 252 |
?> |
| 253 |
</p> |
| 254 |
</div> |
| 255 |
<?php |
| 256 |
endif; |
| 257 |
|
| 258 |
/** |
| 259 |
* Fires after the post time/date setting in the Publish meta box. |
| 260 |
* |
| 261 |
* @since 2.9.0 |
| 262 |
* @since 4.4.0 Added the `$post` parameter. |
| 263 |
* |
| 264 |
* @param WP_Post $post WP_Post object for the current post. |
| 265 |
*/ |
| 266 |
do_action( 'post_submitbox_misc_actions', $post ); |
| 267 |
?> |
| 268 |
</div> |
| 269 |
<div class="clear"></div> |
| 270 |
</div> |
| 271 |
|
| 272 |
<div id="major-publishing-actions"> |
| 273 |
<?php |
| 274 |
/** |
| 275 |
* Fires at the beginning of the publishing actions section of the Publish meta box. |
| 276 |
* |
| 277 |
* @since 2.7.0 |
| 278 |
* @since 4.9.0 Added the `$post` parameter. |
| 279 |
* |
| 280 |
* @param WP_Post|null $post WP_Post object for the current post on Edit Post screen, |
| 281 |
* null on Edit Link screen. |
| 282 |
*/ |
| 283 |
do_action( 'post_submitbox_start', $post ); |
| 284 |
?> |
| 285 |
<div class="duplicate-filter-set"> |
| 286 |
<?php |
| 287 |
$is_filter_set_post = ($post->post_type === FLRT_FILTERS_SET_POST_TYPE); |
| 288 |
$can_duplicate = current_user_can('delete_post', $post->ID); |
| 289 |
$is_pro_version = defined('FLRT_FILTERS_PRO') && FLRT_FILTERS_PRO; |
| 290 |
|
| 291 |
if ($is_filter_set_post && $can_duplicate) : |
| 292 |
$label = esc_html__('Duplicate Filter Set', 'filter-everything'); |
| 293 |
|
| 294 |
if ($is_pro_version) : |
| 295 |
$query_args = ['action' => 'flrt_duplicate_filter_set', 'post' => $post->ID]; |
| 296 |
$base_url = add_query_arg($query_args, admin_url('admin.php')); |
| 297 |
$url = wp_nonce_url($base_url, 'flrt_duplicate_filter_set'); |
| 298 |
?> |
| 299 |
<a href="<?php echo esc_url($url); ?>"> |
| 300 |
<span class="flrt-duplicate-filter-set">+</span> <?php echo $label; ?> |
| 301 |
</a> |
| 302 |
<?php else : ?> |
| 303 |
<a href="<?php echo esc_url(flrt_vailable_in_pro_attr_link());?>" class="wpc-vailable-in-pro-link"> |
| 304 |
<span class="flrt-duplicate-filter-set">+</span> |
| 305 |
<?php echo $label; ?> |
| 306 |
<?php echo '(' . esc_html__('PRO', 'filter-everything') . ')'; ?> |
| 307 |
</a> |
| 308 |
<?php endif; |
| 309 |
endif; ?> |
| 310 |
</div> |
| 311 |
<div id="delete-action"> |
| 312 |
<?php |
| 313 |
if ( current_user_can( 'delete_post', $post_id ) ) { |
| 314 |
if ( ! EMPTY_TRASH_DAYS ) { |
| 315 |
$delete_text = esc_html__( 'Delete permanently' ); |
| 316 |
} else { |
| 317 |
$delete_text = esc_html__( 'Move to Trash' ); |
| 318 |
} |
| 319 |
?> |
| 320 |
<a class="submitdelete deletion" href="<?php echo get_delete_post_link( $post_id ); ?>"><?php echo esc_html( $delete_text ); ?></a> |
| 321 |
<?php |
| 322 |
} |
| 323 |
?> |
| 324 |
</div> |
| 325 |
|
| 326 |
<div id="publishing-action"<?php echo ($under_limit_filter_set) ? ' class="wpc_under_limit_filter_set_publish"' : ''; ?>> |
| 327 |
<span class="spinner"></span> |
| 328 |
<?php |
| 329 |
$button_text = ''; |
| 330 |
if ( ! in_array( $post->post_status, array( 'publish', 'future', 'private' ), true ) || 0 === $post_id ) { |
| 331 |
if ( $can_publish ) : |
| 332 |
if ( ! empty( $post->post_date_gmt ) && time() < strtotime( $post->post_date_gmt . ' +0000' ) ) : |
| 333 |
?> |
| 334 |
<input name="original_publish" type="hidden" id="original_publish" value="<?php echo esc_attr_x( 'Schedule', 'post action/button label' ); ?>" /> |
| 335 |
<?php |
| 336 |
$button_text = _x( 'Schedule', 'post action/button label' ); |
| 337 |
submit_button( $button_text, 'primary large', 'publish', false ); ?> |
| 338 |
<?php |
| 339 |
else : |
| 340 |
?> |
| 341 |
<input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e( 'Publish' ); ?>" /> |
| 342 |
<?php |
| 343 |
$button_text = esc_html__( 'Publish' ); |
| 344 |
submit_button( esc_html__( 'Publish' ), 'primary large', 'publish', false ); ?> |
| 345 |
<?php |
| 346 |
endif; |
| 347 |
else : |
| 348 |
?> |
| 349 |
<input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e( 'Submit for Review' ); ?>" /> |
| 350 |
<?php |
| 351 |
$button_text = esc_html__( 'Submit for Review' ); |
| 352 |
submit_button( esc_html__( 'Submit for Review' ), 'primary large', 'publish', false ); ?> |
| 353 |
<?php |
| 354 |
endif; |
| 355 |
} else { |
| 356 |
?> |
| 357 |
<input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e( 'Update' ); ?>" /> |
| 358 |
<?php |
| 359 |
$button_text = esc_html__( 'Update' ); |
| 360 |
submit_button( esc_html__( 'Update' ), 'primary large', 'save', false, array( 'id' => 'publish' ) ); ?> |
| 361 |
<?php |
| 362 |
} |
| 363 |
?> |
| 364 |
<?php |
| 365 |
if(!defined('FLRT_FILTERS_PRO')){ |
| 366 |
if ( $under_limit_filter_set ) { |
| 367 |
echo flrt_unlock_in_pro($button_text); |
| 368 |
} |
| 369 |
} ?> |
| 370 |
</div> |
| 371 |
<div class="clear"></div> |
| 372 |
</div> |
| 373 |
|
| 374 |
</div> |
| 375 |
<?php |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
new MetaBoxes(); |