| 1 |
<?php |
| 2 |
|
| 3 |
class SimpleTags_Related_Post |
| 4 |
{ |
| 5 |
|
| 6 |
const MENU_SLUG = 'st_options'; |
| 7 |
|
| 8 |
// class instance |
| 9 |
static $instance; |
| 10 |
|
| 11 |
// WP_List_Table object |
| 12 |
public $terms_table; |
| 13 |
|
| 14 |
/** |
| 15 |
* Constructor |
| 16 |
* |
| 17 |
* @return void |
| 18 |
* @author Olatechpro |
| 19 |
*/ |
| 20 |
public function __construct() |
| 21 |
{ |
| 22 |
|
| 23 |
add_filter('set-screen-option', [__CLASS__, 'set_screen'], 10, 3); |
| 24 |
// Admin menu |
| 25 |
add_action('admin_menu', [$this, 'admin_menu']); |
| 26 |
|
| 27 |
// Javascript |
| 28 |
add_action('admin_enqueue_scripts', [__CLASS__, 'admin_enqueue_scripts'], 11); |
| 29 |
|
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Init somes JS and CSS need for this feature |
| 34 |
* |
| 35 |
* @return void |
| 36 |
* @author Olatechpro |
| 37 |
*/ |
| 38 |
public static function admin_enqueue_scripts() |
| 39 |
{ |
| 40 |
|
| 41 |
// add JS for manage click tags |
| 42 |
if (isset($_GET['page']) && $_GET['page'] == 'st_related_posts') { |
| 43 |
wp_enqueue_style('st-taxonomies-css'); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
public static function set_screen($status, $option, $value) |
| 48 |
{ |
| 49 |
return $value; |
| 50 |
} |
| 51 |
|
| 52 |
/** Singleton instance */ |
| 53 |
public static function get_instance() |
| 54 |
{ |
| 55 |
if (!isset(self::$instance)) { |
| 56 |
self::$instance = new self(); |
| 57 |
} |
| 58 |
|
| 59 |
return self::$instance; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Add WP admin menu for Tags |
| 64 |
* |
| 65 |
* @return void |
| 66 |
* @author Olatechpro |
| 67 |
*/ |
| 68 |
public function admin_menu() |
| 69 |
{ |
| 70 |
$hook = add_submenu_page( |
| 71 |
self::MENU_SLUG, |
| 72 |
esc_html__('Related Posts', 'simple-tags'), |
| 73 |
esc_html__('Related Posts', 'simple-tags'), |
| 74 |
'simple_tags', |
| 75 |
'st_related_posts', |
| 76 |
[ |
| 77 |
$this, |
| 78 |
'page_manage_relatedposts', |
| 79 |
] |
| 80 |
); |
| 81 |
|
| 82 |
if(taxopress_is_screen_main_page()){ |
| 83 |
add_action("load-$hook", [$this, 'screen_option']); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Screen options |
| 89 |
*/ |
| 90 |
public function screen_option() |
| 91 |
{ |
| 92 |
|
| 93 |
$option = 'per_page'; |
| 94 |
$args = [ |
| 95 |
'label' => esc_html__('Number of items per page', 'simple-tags'), |
| 96 |
'default' => 20, |
| 97 |
'option' => 'st_related_posts_per_page' |
| 98 |
]; |
| 99 |
|
| 100 |
add_screen_option($option, $args); |
| 101 |
|
| 102 |
$this->terms_table = new RelatedPosts_List(); |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Method for build the page HTML manage tags |
| 107 |
* |
| 108 |
* @return void |
| 109 |
* @author Olatechpro |
| 110 |
*/ |
| 111 |
public function page_manage_relatedposts() |
| 112 |
{ |
| 113 |
// Default order |
| 114 |
if (!isset($_GET['order'])) { |
| 115 |
$_GET['order'] = 'name-asc'; |
| 116 |
} |
| 117 |
|
| 118 |
settings_errors(__CLASS__); |
| 119 |
|
| 120 |
if (!isset($_GET['add'])) { |
| 121 |
//all tax |
| 122 |
?> |
| 123 |
<div class="wrap st_wrap st-manage-taxonomies-page"> |
| 124 |
|
| 125 |
<div id=""> |
| 126 |
<h1 class="wp-heading-inline"><?php _e('Related Posts', 'simple-tags'); ?></h1> |
| 127 |
<a href="<?php echo esc_url(admin_url('admin.php?page=st_related_posts&add=new_item')); ?>" |
| 128 |
class="page-title-action"><?php esc_html_e('Add New', 'simple-tags'); ?></a> |
| 129 |
|
| 130 |
<div class="taxopress-description"><?php esc_html_e('The Related Posts feature works by checking for shared taxonomy terms. If your post has the terms “WordPress” and “Website”, then Related Posts will display other posts that also have the terms “WordPress” and “Website”.', 'simple-tags'); ?></div> |
| 131 |
|
| 132 |
|
| 133 |
<?php |
| 134 |
if (isset($_REQUEST['s']) && $search = sanitize_text_field(wp_unslash($_REQUEST['s']))) { |
| 135 |
/* translators: %s: search keywords */ |
| 136 |
printf(' <span class="subtitle">' . esc_html__('Search results for “%s”', |
| 137 |
'simple-tags') . '</span>', esc_html($search)); |
| 138 |
} |
| 139 |
?> |
| 140 |
<?php |
| 141 |
|
| 142 |
//the terms table instance |
| 143 |
$this->terms_table->prepare_items(); |
| 144 |
?> |
| 145 |
|
| 146 |
|
| 147 |
<hr class="wp-header-end"> |
| 148 |
<div id="ajax-response"></div> |
| 149 |
<form class="search-form wp-clearfix st-taxonomies-search-form" method="get"> |
| 150 |
<?php $this->terms_table->search_box(__('Search Related Posts', 'simple-tags'), 'term'); ?> |
| 151 |
</form> |
| 152 |
<div class="clear"></div> |
| 153 |
|
| 154 |
<div id="col-container" class="wp-clearfix"> |
| 155 |
|
| 156 |
<div class="col-wrap"> |
| 157 |
<form action="<?php echo esc_url(add_query_arg('', '')); ?>" method="post"> |
| 158 |
<?php $this->terms_table->display(); //Display the table ?> |
| 159 |
</form> |
| 160 |
<div class="form-wrap edit-term-notes"> |
| 161 |
<p><?php esc_html__('Description here.', 'simple-tags') ?></p> |
| 162 |
</div> |
| 163 |
</div> |
| 164 |
|
| 165 |
|
| 166 |
</div> |
| 167 |
|
| 168 |
|
| 169 |
</div> |
| 170 |
<?php } else { |
| 171 |
if ($_GET['add'] == 'new_item') { |
| 172 |
//add/edit taxonomy |
| 173 |
$this->taxopress_manage_relatedposts(); |
| 174 |
echo '<div>'; |
| 175 |
} |
| 176 |
} ?> |
| 177 |
|
| 178 |
|
| 179 |
<?php SimpleTags_Admin::printAdminFooter(); ?> |
| 180 |
</div> |
| 181 |
<?php |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
/** |
| 186 |
* Create our settings page output. |
| 187 |
* |
| 188 |
* @internal |
| 189 |
*/ |
| 190 |
public function taxopress_manage_relatedposts() |
| 191 |
{ |
| 192 |
|
| 193 |
$tab = (!empty($_GET) && !empty($_GET['action']) && 'edit' == $_GET['action']) ? 'edit' : 'new'; |
| 194 |
$tab_class = 'taxopress-' . $tab; |
| 195 |
$current = null; |
| 196 |
|
| 197 |
?> |
| 198 |
|
| 199 |
<div class="wrap <?php echo esc_attr($tab_class); ?>"> |
| 200 |
|
| 201 |
<?php |
| 202 |
|
| 203 |
$relatedposts = taxopress_get_relatedpost_data(); |
| 204 |
$related_post_edit = false; |
| 205 |
$related_post_limit = false; |
| 206 |
|
| 207 |
if ('edit' === $tab) { |
| 208 |
|
| 209 |
|
| 210 |
$selected_relatedpost = taxopress_get_current_relatedpost(); |
| 211 |
|
| 212 |
if ($selected_relatedpost && array_key_exists($selected_relatedpost, $relatedposts)) { |
| 213 |
$current = $relatedposts[$selected_relatedpost]; |
| 214 |
$related_post_edit = true; |
| 215 |
} |
| 216 |
|
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
if (!isset($current['title']) && count($relatedposts) > 0 && apply_filters('taxopress_related_posts_create_limit', true)) { |
| 221 |
$related_post_limit = true; |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
$ui = new taxopress_admin_ui(); |
| 226 |
?> |
| 227 |
|
| 228 |
|
| 229 |
<div class="wrap <?php echo esc_attr($tab_class); ?>"> |
| 230 |
<h1><?php echo esc_html__('Manage Related Posts', 'simple-tags'); ?></h1> |
| 231 |
<div class="wp-clearfix"></div> |
| 232 |
|
| 233 |
<form method="post" action=""> |
| 234 |
|
| 235 |
|
| 236 |
<div class="tagcloudui st-tabbed"> |
| 237 |
|
| 238 |
<div class="relatedposts-postbox-container"> |
| 239 |
<div id="poststuff"> |
| 240 |
<div class="taxopress-section postbox"> |
| 241 |
<div class="postbox-header"> |
| 242 |
<h2 class="hndle ui-sortable-handle"> |
| 243 |
<?php |
| 244 |
if ($related_post_edit) { |
| 245 |
$active_tab = ( isset($current['active_tab']) && !empty(trim($current['active_tab'])) ) ? $current['active_tab'] : 'relatedpost_general'; |
| 246 |
echo esc_html__('Edit Related Posts', 'simple-tags'); |
| 247 |
echo '<input type="hidden" name="edited_relatedpost" value="' . esc_attr($current['ID']) . '" />'; |
| 248 |
echo '<input type="hidden" name="taxopress_related_post[ID]" value="' . esc_attr($current['ID']) . '" />'; |
| 249 |
echo '<input type="hidden" name="taxopress_related_post[active_tab]" class="taxopress-active-subtab" value="'.esc_attr($active_tab).'" />'; |
| 250 |
} else { |
| 251 |
$active_tab = 'relatedpost_general'; |
| 252 |
echo '<input type="hidden" name="taxopress_related_post[active_tab]" class="taxopress-active-subtab" value="" />'; |
| 253 |
echo esc_html__('Add new Related Posts', 'simple-tags'); |
| 254 |
} |
| 255 |
?> |
| 256 |
</h2> |
| 257 |
</div> |
| 258 |
<div class="inside"> |
| 259 |
<div class="main"> |
| 260 |
|
| 261 |
|
| 262 |
<?php if ($related_post_limit) { |
| 263 |
echo '<div class="taxopress-warning upgrade-pro"> |
| 264 |
<p> |
| 265 |
|
| 266 |
<h2 style="margin-bottom: 5px;">' . esc_html__('To create more Related Posts, please upgrade to TaxoPress Pro.', |
| 267 |
'simple-tags') . '</h2> |
| 268 |
' . esc_html__('With TaxoPress Pro, you can create unlimited Related Posts. You can create Related Posts for any taxonomy and then display those Related Posts anywhere on your site.', |
| 269 |
'simple-tags') . ' |
| 270 |
|
| 271 |
</p> |
| 272 |
</div>'; |
| 273 |
|
| 274 |
} else { |
| 275 |
?> |
| 276 |
|
| 277 |
|
| 278 |
<ul class="taxopress-tab"> |
| 279 |
<li class="relatedpost_general_tab <?php echo $active_tab === 'relatedpost_general' ? 'active' : ''; ?>" data-content="relatedpost_general"> |
| 280 |
<a href="#relatedpost_general"><span><?php esc_html_e('General', |
| 281 |
'simple-tags'); ?></span></a> |
| 282 |
</li> |
| 283 |
|
| 284 |
<li class="relatedpost_display_tab <?php echo $active_tab === 'relatedpost_display' ? 'active' : ''; ?>" data-content="relatedpost_display"> |
| 285 |
<a href="#relatedpost_display"><span><?php esc_html_e('Display', |
| 286 |
'simple-tags'); ?></span></a> |
| 287 |
</li> |
| 288 |
|
| 289 |
<li class="relatedpost_option_tab <?php echo $active_tab === 'relatedpost_option' ? 'active' : ''; ?>" data-content="relatedpost_option"> |
| 290 |
<a href="#relatedpost_option"><span><?php esc_html_e('Options', |
| 291 |
'simple-tags'); ?></span></a> |
| 292 |
</li> |
| 293 |
|
| 294 |
<li class="relatedpost_advanced_tab <?php echo $active_tab === 'relatedpost_advanced' ? 'active' : ''; ?>" data-content="relatedpost_advanced"> |
| 295 |
<a href="#relatedpost_advanced"><span><?php esc_html_e('Advanced', |
| 296 |
'simple-tags'); ?></span></a> |
| 297 |
</li> |
| 298 |
|
| 299 |
</ul> |
| 300 |
|
| 301 |
<div class="st-taxonomy-content taxopress-tab-content"> |
| 302 |
|
| 303 |
|
| 304 |
<table class="form-table taxopress-table relatedpost_general" |
| 305 |
style="<?php echo $active_tab === 'relatedpost_general' ? '' : 'display:none;'; ?>"> |
| 306 |
<?php |
| 307 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 308 |
echo $ui->get_tr_start(); |
| 309 |
|
| 310 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 311 |
echo $ui->get_th_start(); |
| 312 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 313 |
echo $ui->get_label('name', esc_html__('Title', 'simple-tags')) . $ui->get_required_span(); |
| 314 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 315 |
echo $ui->get_th_end() . $ui->get_td_start(); |
| 316 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 317 |
echo $ui->get_text_input([ |
| 318 |
'namearray' => 'taxopress_related_post', |
| 319 |
'name' => 'title', |
| 320 |
'textvalue' => isset($current['title']) ? esc_attr($current['title']) : '', |
| 321 |
'maxlength' => '32', |
| 322 |
'helptext' => '', |
| 323 |
'required' => true, |
| 324 |
'placeholder' => false, |
| 325 |
'wrap' => false, |
| 326 |
]); |
| 327 |
|
| 328 |
|
| 329 |
$select = [ |
| 330 |
'options' => [ |
| 331 |
[ |
| 332 |
'attr' => '', |
| 333 |
'text' => esc_attr__('None', 'simple-tags') |
| 334 |
], |
| 335 |
[ |
| 336 |
'attr' => 'h1', |
| 337 |
'text' => esc_attr__('H1', 'simple-tags') |
| 338 |
], |
| 339 |
[ |
| 340 |
'attr' => 'h2', |
| 341 |
'text' => esc_attr__('H2', 'simple-tags') |
| 342 |
], |
| 343 |
[ |
| 344 |
'attr' => 'h3', |
| 345 |
'text' => esc_attr__('H3', 'simple-tags') |
| 346 |
], |
| 347 |
[ |
| 348 |
'attr' => 'h4', |
| 349 |
'text' => esc_attr__('H4', 'simple-tags'), |
| 350 |
'default' => 'true' |
| 351 |
], |
| 352 |
[ |
| 353 |
'attr' => 'h5', |
| 354 |
'text' => esc_attr__('H5', 'simple-tags') |
| 355 |
], |
| 356 |
[ |
| 357 |
'attr' => 'h6', |
| 358 |
'text' => esc_attr__('H6', 'simple-tags') |
| 359 |
], |
| 360 |
], |
| 361 |
]; |
| 362 |
$selected = isset($current) ? taxopress_disp_boolean($current['title_header']) : ''; |
| 363 |
|
| 364 |
$select['selected'] = !empty($selected) ? $current['title_header'] : ''; |
| 365 |
if(isset($current['title_header']) && empty($current['title_header'])){ |
| 366 |
$select['selected'] = 'none'; |
| 367 |
} |
| 368 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 369 |
echo $ui->get_select_checkbox_input_main([ |
| 370 |
'namearray' => 'taxopress_related_post', |
| 371 |
'name' => 'title_header', |
| 372 |
'labeltext' => esc_html__('Title header', 'simple-tags'), |
| 373 |
'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 374 |
]); |
| 375 |
|
| 376 |
$options[] = [ |
| 377 |
'attr' => 'st_all_posttype', |
| 378 |
'text' => esc_html__('All post types', 'simple-tags') |
| 379 |
]; |
| 380 |
$options[] = [ |
| 381 |
'attr' => 'st_current_posttype', |
| 382 |
'text' => esc_html__('Current post type', 'simple-tags'), |
| 383 |
'default' => 'true' |
| 384 |
]; |
| 385 |
foreach (get_post_types(['public' => true], |
| 386 |
'objects') as $post_type) { |
| 387 |
$options[] = [ |
| 388 |
'attr' => $post_type->name, |
| 389 |
'text' => $post_type->label |
| 390 |
]; |
| 391 |
} |
| 392 |
|
| 393 |
$select = [ |
| 394 |
'options' => $options, |
| 395 |
]; |
| 396 |
$selected = (isset($current) && isset($current['post_type'])) ? taxopress_disp_boolean($current['post_type']) : ''; |
| 397 |
$select['selected'] = !empty($selected) ? $current['post_type'] : ''; |
| 398 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 399 |
echo $ui->get_select_checkbox_input_main([ |
| 400 |
'namearray' => 'taxopress_related_post', |
| 401 |
'name' => 'post_type', |
| 402 |
'class' => 'st-post-type-select', |
| 403 |
'labeltext' => esc_html__('Post Type', 'simple-tags'), |
| 404 |
'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 405 |
]); |
| 406 |
|
| 407 |
$options = []; |
| 408 |
foreach (get_all_taxopress_taxonomies() as $_taxonomy) { |
| 409 |
$_taxonomy = $_taxonomy->name; |
| 410 |
$tax = get_taxonomy($_taxonomy); |
| 411 |
if (empty($tax->labels->name)) { |
| 412 |
continue; |
| 413 |
} |
| 414 |
if ($tax->name === 'post_tag') { |
| 415 |
$options[] = [ |
| 416 |
'attr' => $tax->name, |
| 417 |
'text' => $tax->labels->name. ' ('.$tax->name.')', |
| 418 |
'default' => 'true', |
| 419 |
'post_type' => join(',', $tax->object_type), |
| 420 |
]; |
| 421 |
} else { |
| 422 |
$options[] = [ |
| 423 |
'attr' => $tax->name, |
| 424 |
'text' => $tax->labels->name. ' ('.$tax->name.')', |
| 425 |
'post_type' => join(',', $tax->object_type), |
| 426 |
]; |
| 427 |
} |
| 428 |
} |
| 429 |
|
| 430 |
$select = [ |
| 431 |
'options' => $options, |
| 432 |
]; |
| 433 |
$selected = isset($current) ? taxopress_disp_boolean($current['taxonomy']) : ''; |
| 434 |
$select['selected'] = !empty($selected) ? $current['taxonomy'] : ''; |
| 435 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 436 |
echo $ui->get_select_checkbox_input_main([ |
| 437 |
'namearray' => 'taxopress_related_post', |
| 438 |
'name' => 'taxonomy', |
| 439 |
'class' => 'st-post-taxonomy-select', |
| 440 |
'labeltext' => esc_html__('Taxonomy', 'simple-tags'), |
| 441 |
'required' => true, |
| 442 |
'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 443 |
]); |
| 444 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 445 |
echo $ui->get_td_end() . $ui->get_tr_end(); |
| 446 |
?> |
| 447 |
</table> |
| 448 |
|
| 449 |
|
| 450 |
<table class="form-table taxopress-table relatedpost_display" |
| 451 |
style="<?php echo $active_tab === 'relatedpost_display' ? '' : 'display:none;'; ?>"> |
| 452 |
<?php |
| 453 |
|
| 454 |
$select = [ |
| 455 |
'options' => [ |
| 456 |
[ |
| 457 |
'attr' => '0', |
| 458 |
'text' => esc_attr__('False', 'simple-tags'), |
| 459 |
'default' => 'true', |
| 460 |
], |
| 461 |
[ |
| 462 |
'attr' => '1', |
| 463 |
'text' => esc_attr__('True', 'simple-tags'), |
| 464 |
], |
| 465 |
], |
| 466 |
]; |
| 467 |
$selected = (isset($current) && isset($current['hide_title'])) ? taxopress_disp_boolean($current['hide_title']) : ''; |
| 468 |
$select['selected'] = !empty($selected) ? $current['hide_title'] : ''; |
| 469 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 470 |
echo $ui->get_select_checkbox_input([ |
| 471 |
'namearray' => 'taxopress_related_post', |
| 472 |
'name' => 'hide_title', |
| 473 |
'labeltext' => esc_html__('Hide title in output ?', |
| 474 |
'simple-tags'), |
| 475 |
'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 476 |
]); |
| 477 |
|
| 478 |
/** |
| 479 |
* Filters the arguments for post types to list for taxonomy association. |
| 480 |
* |
| 481 |
* |
| 482 |
* @param array $value Array of default arguments. |
| 483 |
*/ |
| 484 |
$args = apply_filters('taxopress_attach_post_types_to_taxonomy', |
| 485 |
['public' => true]); |
| 486 |
|
| 487 |
// If they don't return an array, fall back to the original default. Don't need to check for empty, because empty array is default for $args param in get_post_types anyway. |
| 488 |
if (!is_array($args)) { |
| 489 |
$args = ['public' => true]; |
| 490 |
} |
| 491 |
$output = 'objects'; // Or objects. |
| 492 |
|
| 493 |
/** |
| 494 |
* Filters the results returned to display for available post types for taxonomy. |
| 495 |
* |
| 496 |
* @param array $value Array of post type objects. |
| 497 |
* @param array $args Array of arguments for the post type query. |
| 498 |
* @param string $output The output type we want for the results. |
| 499 |
*/ |
| 500 |
$post_types = apply_filters('taxopress_get_post_types_for_taxonomies', |
| 501 |
get_post_types($args, $output), $args, $output); |
| 502 |
|
| 503 |
$term_auto_locations = [ |
| 504 |
'homeonly' => esc_attr__('Homepage', 'simple-tags'), |
| 505 |
'blogonly' => esc_attr__('Blog display', 'simple-tags'), |
| 506 |
]; |
| 507 |
foreach ($post_types as $post_type) { |
| 508 |
$term_auto_locations[$post_type->name] = $post_type->label; |
| 509 |
} |
| 510 |
|
| 511 |
echo '<tr valign="top"><th scope="row"><label>' . esc_html__('Attempt to automatically display related posts', |
| 512 |
'simple-tags') . '</label><br /><small style=" color: #646970;">' . esc_html__('TaxoPress will attempt to automatically display related posts in this content. It may not be successful for all post types and layouts.', |
| 513 |
'simple-tags') . '</small></th><td> |
| 514 |
<table class="visbile-table">'; |
| 515 |
foreach ($term_auto_locations as $key => $value) { |
| 516 |
|
| 517 |
|
| 518 |
echo '<tr valign="top"><th scope="row"><label for="' . esc_attr($key) . '">' .esc_html($value) . '</label></th><td>'; |
| 519 |
|
| 520 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 521 |
echo $ui->get_check_input([ |
| 522 |
'checkvalue' => esc_attr($key), |
| 523 |
'checked' => (!empty($current['embedded']) && is_array($current['embedded']) && in_array($key, |
| 524 |
$current['embedded'], true)) ? 'true' : 'false', |
| 525 |
'name' => esc_attr($key), |
| 526 |
'namearray' => 'embedded', |
| 527 |
'textvalue' => esc_attr($key), |
| 528 |
'labeltext' => "", |
| 529 |
'wrap' => false, |
| 530 |
]); |
| 531 |
|
| 532 |
echo '</td></tr>'; |
| 533 |
|
| 534 |
if ($key === 'blogonly') { |
| 535 |
echo '<tr valign="top"><th style="padding: 0;" scope="row"><hr /></th><td style="padding: 0;"><hr /></td></tr>'; |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
} |
| 540 |
echo '</table></td></tr>'; |
| 541 |
|
| 542 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 543 |
echo $ui->get_number_input([ |
| 544 |
'namearray' => 'taxopress_related_post', |
| 545 |
'name' => 'number', |
| 546 |
'textvalue' => isset($current['number']) ? esc_attr($current['number']) : '5', |
| 547 |
'labeltext' => esc_html__('Maximum related posts to display', |
| 548 |
'simple-tags'), |
| 549 |
'helptext' => '', |
| 550 |
'required' => true, |
| 551 |
]); |
| 552 |
|
| 553 |
|
| 554 |
?> |
| 555 |
|
| 556 |
</table> |
| 557 |
|
| 558 |
|
| 559 |
<table class="form-table taxopress-table relatedpost_option" |
| 560 |
style="<?php echo $active_tab === 'relatedpost_option' ? '' : 'display:none;'; ?>"> |
| 561 |
<?php |
| 562 |
|
| 563 |
$select = [ |
| 564 |
'options' => [ |
| 565 |
[ |
| 566 |
'attr' => '1', |
| 567 |
'text' => esc_attr__('24 hours', 'simple-tags') |
| 568 |
], |
| 569 |
[ |
| 570 |
'attr' => '7', |
| 571 |
'text' => esc_attr__('7 days', 'simple-tags') |
| 572 |
], |
| 573 |
[ |
| 574 |
'attr' => '14', |
| 575 |
'text' => esc_attr__('2 weeks', 'simple-tags') |
| 576 |
], |
| 577 |
[ |
| 578 |
'attr' => '30', |
| 579 |
'text' => esc_attr__('1 month', 'simple-tags') |
| 580 |
], |
| 581 |
[ |
| 582 |
'attr' => '180', |
| 583 |
'text' => esc_attr__('6 months', 'simple-tags') |
| 584 |
], |
| 585 |
[ |
| 586 |
'attr' => '365', |
| 587 |
'text' => esc_attr__('1 year', 'simple-tags') |
| 588 |
], |
| 589 |
[ |
| 590 |
'attr' => '0', |
| 591 |
'text' => esc_attr__('No limit', 'simple-tags'), |
| 592 |
'default' => 'true' |
| 593 |
], |
| 594 |
], |
| 595 |
]; |
| 596 |
$selected = isset($current) ? taxopress_disp_boolean($current['limit_days']) : ''; |
| 597 |
$select['selected'] = !empty($selected) ? $current['limit_days'] : ''; |
| 598 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 599 |
echo $ui->get_select_number_select([ |
| 600 |
'namearray' => 'taxopress_related_post', |
| 601 |
'name' => 'limit_days', |
| 602 |
'labeltext' => esc_html__('Limit related posts based on timeframe', |
| 603 |
'simple-tags'), |
| 604 |
'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 605 |
]); |
| 606 |
|
| 607 |
|
| 608 |
$select = [ |
| 609 |
'options' => [ |
| 610 |
[ |
| 611 |
'attr' => 'count-asc', |
| 612 |
'text' => esc_attr__('Least common tags between posts', |
| 613 |
'simple-tags') |
| 614 |
], |
| 615 |
[ |
| 616 |
'attr' => 'count-desc', |
| 617 |
'text' => esc_attr__('Most common tags between posts', |
| 618 |
'simple-tags'), |
| 619 |
'default' => 'true' |
| 620 |
], |
| 621 |
[ |
| 622 |
'attr' => 'date-asc', |
| 623 |
'text' => esc_attr__('Older Entries', 'simple-tags') |
| 624 |
], |
| 625 |
[ |
| 626 |
'attr' => 'date-desc', |
| 627 |
'text' => esc_attr__('Newer Entries', 'simple-tags') |
| 628 |
], |
| 629 |
[ |
| 630 |
'attr' => 'name-asc', |
| 631 |
'text' => esc_attr__('Alphabetical', 'simple-tags') |
| 632 |
], |
| 633 |
[ |
| 634 |
'attr' => 'name-desc', |
| 635 |
'text' => esc_attr__('Inverse Alphabetical', |
| 636 |
'simple-tags') |
| 637 |
], |
| 638 |
[ |
| 639 |
'attr' => 'random', |
| 640 |
'text' => esc_attr__('Random', 'simple-tags') |
| 641 |
], |
| 642 |
], |
| 643 |
]; |
| 644 |
$selected = isset($current) ? taxopress_disp_boolean($current['order']) : ''; |
| 645 |
$select['selected'] = !empty($selected) ? $current['order'] : ''; |
| 646 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 647 |
echo $ui->get_select_checkbox_input_main([ |
| 648 |
'namearray' => 'taxopress_related_post', |
| 649 |
'name' => 'order', |
| 650 |
'labeltext' => esc_html__('Related Posts Order', |
| 651 |
'simple-tags'), |
| 652 |
'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 653 |
]); |
| 654 |
|
| 655 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 656 |
echo $ui->get_text_input([ |
| 657 |
'namearray' => 'taxopress_related_post', |
| 658 |
'name' => 'nopoststext', |
| 659 |
'textvalue' => isset($current['nopoststext']) ? esc_attr($current['nopoststext']) : 'No related posts.', |
| 660 |
'labeltext' => esc_html__('Text to show when there is no related post', |
| 661 |
'simple-tags'), |
| 662 |
'helptext' => '', |
| 663 |
'required' => false, |
| 664 |
]); |
| 665 |
|
| 666 |
|
| 667 |
$select = [ |
| 668 |
'options' => [ |
| 669 |
[ |
| 670 |
'attr' => '0', |
| 671 |
'text' => esc_attr__('False', 'simple-tags'), |
| 672 |
'default' => 'true', |
| 673 |
], |
| 674 |
[ |
| 675 |
'attr' => '1', |
| 676 |
'text' => esc_attr__('True', 'simple-tags'), |
| 677 |
], |
| 678 |
], |
| 679 |
]; |
| 680 |
$selected = (isset($current) && isset($current['hide_output'])) ? taxopress_disp_boolean($current['hide_output']) : ''; |
| 681 |
$select['selected'] = !empty($selected) ? $current['hide_output'] : ''; |
| 682 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 683 |
echo $ui->get_select_checkbox_input([ |
| 684 |
'namearray' => 'taxopress_related_post', |
| 685 |
'name' => 'hide_output', |
| 686 |
'labeltext' => esc_html__('Hide output if no related post is found ?', |
| 687 |
'simple-tags'), |
| 688 |
'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 689 |
]); |
| 690 |
|
| 691 |
|
| 692 |
?> |
| 693 |
|
| 694 |
</table> |
| 695 |
|
| 696 |
|
| 697 |
<table class="form-table taxopress-table relatedpost_advanced" |
| 698 |
style="<?php echo $active_tab === 'relatedpost_advanced' ? '' : 'display:none;'; ?>"> |
| 699 |
<?php |
| 700 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 701 |
echo $ui->get_text_input([ |
| 702 |
'namearray' => 'taxopress_related_post', |
| 703 |
'name' => 'wrap_class', |
| 704 |
'class' => '', |
| 705 |
'textvalue' => isset($current['wrap_class']) ? esc_attr($current['wrap_class']) : '', |
| 706 |
'labeltext' => esc_html__('Related Posts div class', 'simple-tags'), |
| 707 |
'helptext' => '', |
| 708 |
'required' => false, |
| 709 |
]); |
| 710 |
|
| 711 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 712 |
echo $ui->get_text_input([ |
| 713 |
'namearray' => 'taxopress_related_post', |
| 714 |
'name' => 'link_class', |
| 715 |
'class' => '', |
| 716 |
'textvalue' => isset($current['link_class']) ? esc_attr($current['link_class']) : '', |
| 717 |
'labeltext' => esc_html__('Term link class', 'simple-tags'), |
| 718 |
'helptext' => '', |
| 719 |
'required' => false, |
| 720 |
]); |
| 721 |
|
| 722 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 723 |
echo $ui->get_textarea_input([ |
| 724 |
'namearray' => 'taxopress_related_post', |
| 725 |
'name' => 'xformat', |
| 726 |
'class' => 'st-full-width', |
| 727 |
'rows' => '4', |
| 728 |
'cols' => '40', |
| 729 |
'textvalue' => isset($current['xformat']) ? esc_attr($current['xformat']) : esc_attr('<a href="%post_permalink%" title="%post_title% (%post_date%)">%post_title%</a>'), |
| 730 |
'labeltext' => esc_html__('Term link format', 'simple-tags'), |
| 731 |
'helptext' => sprintf(esc_html__('You can find markers and explanations %1sin the documentation%2s.', 'simple-tags'), '<a target="blank" href="https://taxopress.com/docs/format-related-posts/">', '</a>'), |
| 732 |
'required' => false, |
| 733 |
]); |
| 734 |
|
| 735 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 736 |
echo $ui->get_td_end() . $ui->get_tr_end(); |
| 737 |
?> |
| 738 |
</table> |
| 739 |
|
| 740 |
|
| 741 |
</div> |
| 742 |
|
| 743 |
|
| 744 |
<?php }//end new fields |
| 745 |
?> |
| 746 |
|
| 747 |
|
| 748 |
<div class="clear"></div> |
| 749 |
|
| 750 |
|
| 751 |
</div> |
| 752 |
</div> |
| 753 |
</div> |
| 754 |
|
| 755 |
|
| 756 |
<?php if ($related_post_limit) { ?> |
| 757 |
|
| 758 |
<div class="pp-version-notice-bold-purple" style="margin-left:0px;"> |
| 759 |
<div class="pp-version-notice-bold-purple-message"><?php echo esc_html__('You\'re using TaxoPress Free. |
| 760 |
The Pro version has more features and support.', 'simple-tags'); ?> |
| 761 |
</div> |
| 762 |
<div class="pp-version-notice-bold-purple-button"><a |
| 763 |
href="https://taxopress.com/pro" target="_blank"><?php echo esc_html__('Upgrade to Pro', 'simple-tags'); ?></a> |
| 764 |
</div> |
| 765 |
</div> |
| 766 |
|
| 767 |
<?php } ?> |
| 768 |
<?php |
| 769 |
/** |
| 770 |
* Fires after the default fieldsets on the taxonomy screen. |
| 771 |
* |
| 772 |
* @param taxopress_admin_ui $ui Admin UI instance. |
| 773 |
*/ |
| 774 |
do_action('taxopress_taxonomy_after_fieldsets', $ui); |
| 775 |
?> |
| 776 |
|
| 777 |
</div> |
| 778 |
</div> |
| 779 |
|
| 780 |
|
| 781 |
</div> |
| 782 |
|
| 783 |
<div class="taxopress-right-sidebar"> |
| 784 |
<div class="taxopress-right-sidebar-wrapper" style="min-height: 205px;"> |
| 785 |
|
| 786 |
|
| 787 |
<?php |
| 788 |
if (!$related_post_limit){ ?> |
| 789 |
<p class="submit"> |
| 790 |
|
| 791 |
<?php |
| 792 |
wp_nonce_field('taxopress_addedit_relatedpost_nonce_action', |
| 793 |
'taxopress_addedit_relatedpost_nonce_field'); |
| 794 |
if (!empty($_GET) && !empty($_GET['action']) && 'edit' === $_GET['action']) { ?> |
| 795 |
<input type="submit" class="button-primary taxopress-taxonomy-submit taxopress-relatedposts-submit" |
| 796 |
name="relatedpost_submit" |
| 797 |
value="<?php echo esc_attr(esc_attr__('Save Related Posts', |
| 798 |
'simple-tags')); ?>"/> |
| 799 |
<?php |
| 800 |
} else { ?> |
| 801 |
<input type="submit" class="button-primary taxopress-taxonomy-submit taxopress-relatedposts-submit" |
| 802 |
name="relatedpost_submit" |
| 803 |
value="<?php echo esc_attr(esc_attr__('Add Related Posts', |
| 804 |
'simple-tags')); ?>"/> |
| 805 |
<?php } ?> |
| 806 |
|
| 807 |
<input type="hidden" name="cpt_tax_status" id="cpt_tax_status" |
| 808 |
value="<?php echo esc_attr($tab); ?>"/> |
| 809 |
</p> |
| 810 |
|
| 811 |
<?php if (!empty($current)) { |
| 812 |
?> |
| 813 |
<p> |
| 814 |
<?php echo '<div class="taxopress-warning" style="">' . esc_html__('Shortcode: ', |
| 815 |
'simple-tags'); ?> |
| 816 |
<textarea |
| 817 |
style="resize: none;padding: 5px;">[taxopress_relatedposts id="<?php echo (int)$current['ID']; ?>"]</textarea> |
| 818 |
</div> |
| 819 |
</p> |
| 820 |
<?php } ?> |
| 821 |
|
| 822 |
<?php |
| 823 |
} |
| 824 |
?> |
| 825 |
|
| 826 |
</div> |
| 827 |
|
| 828 |
<div class="taxopress-token-right-sidebar"> |
| 829 |
<div id="postbox-container-1" class="postbox-container"> |
| 830 |
<div class="meta-box-sortables"> |
| 831 |
<div class="postbox"> |
| 832 |
<div class="postbox-header"> |
| 833 |
<h3 class="hndle is-non-sortable"> |
| 834 |
<span><?php echo esc_html__('Related Posts format', 'simple-tags'); ?></span> |
| 835 |
</h3> |
| 836 |
</div> |
| 837 |
|
| 838 |
<div class="inside"> |
| 839 |
<p><?php echo esc_html__('Here are the tokens you can use for related posts format', 'simple-tags'); ?>:</p> |
| 840 |
<ul> |
| 841 |
<li><code>%post_permalink%</code> <?php echo esc_html__('The URL of the post', 'simple-tags'); ?></li> |
| 842 |
<li><code>%post_title%</code> <?php echo esc_html__('The title of the post', 'simple-tags'); ?></li> |
| 843 |
<li><code>%post_date% </code><?php echo esc_html__('The date of the post (this shows inside a tooltip)', 'simple-tags'); ?></li> |
| 844 |
<li><code>%post_tagcount%</code> <?php echo esc_html__('The number of tags used by both posts', 'simple-tags'); ?></li> |
| 845 |
<li><code>%post_comment%</code> <?php echo esc_html__('The number of comments on the post', 'simple-tags'); ?></li> |
| 846 |
<li><code>%post_id%</code> <?php echo esc_html__('The ID of the post', 'simple-tags'); ?></li> |
| 847 |
<li><code>%post_relatedtags%</code> <?php echo esc_html__('A list of tags used by both the current post and the related post', 'simple-tags'); ?></li> |
| 848 |
<li><code>%post_excerpt%</code> <?php echo esc_html__('The post excerpt', 'simple-tags'); ?></li> |
| 849 |
</ul> |
| 850 |
</div> |
| 851 |
</div> |
| 852 |
</div> |
| 853 |
</div> |
| 854 |
</div> |
| 855 |
|
| 856 |
<?php do_action('taxopress_admin_after_sidebar'); ?> |
| 857 |
</div> |
| 858 |
|
| 859 |
<div class="clear"></div> |
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
</form> |
| 864 |
|
| 865 |
</div><!-- End .wrap --> |
| 866 |
|
| 867 |
<div class="clear"></div> |
| 868 |
|
| 869 |
<?php # Modal Windows; ?> |
| 870 |
<div class="remodal" data-remodal-id="taxopress-modal-alert" |
| 871 |
data-remodal-options="hashTracking: false, closeOnOutsideClick: false"> |
| 872 |
<div class="" style="color:red;"><?php echo esc_html__('Please complete the following required fields to save your changes:', 'simple-tags'); ?></div> |
| 873 |
<div id="taxopress-modal-alert-content"></div> |
| 874 |
<br> |
| 875 |
<button data-remodal-action="cancel" class="remodal-cancel"><?php echo esc_html__('Okay', 'simple-tags'); ?></button> |
| 876 |
</div> |
| 877 |
|
| 878 |
<div class="remodal" data-remodal-id="taxopress-modal-confirm" |
| 879 |
data-remodal-options="hashTracking: false, closeOnOutsideClick: false"> |
| 880 |
<div id="taxopress-modal-confirm-content"></div> |
| 881 |
<br> |
| 882 |
<button data-remodal-action="cancel" class="remodal-cancel"><?php echo esc_html__('No', 'simple-tags'); ?></button> |
| 883 |
<button data-remodal-action="confirm" |
| 884 |
class="remodal-confirm"><?php echo esc_html__('Yes', 'simple-tags'); ?></button> |
| 885 |
</div> |
| 886 |
<?php |
| 887 |
} |
| 888 |
|
| 889 |
} |
| 890 |
|