| 1 |
<?php |
| 2 |
/** |
| 3 |
* Common class. |
| 4 |
* |
| 5 |
* @package WPZinc\Social |
| 6 |
* @author WP Zinc |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace WPZinc\Social; |
| 10 |
|
| 11 |
/** |
| 12 |
* Common functions that don't fit into other classes. |
| 13 |
* |
| 14 |
* @package WPZinc\Social |
| 15 |
* @author WP Zinc |
| 16 |
* @version 3.0.0 |
| 17 |
*/ |
| 18 |
class Common { |
| 19 |
|
| 20 |
/** |
| 21 |
* Holds the base class object. |
| 22 |
* |
| 23 |
* @since 3.4.7 |
| 24 |
* |
| 25 |
* @var object |
| 26 |
*/ |
| 27 |
public $base; |
| 28 |
|
| 29 |
/** |
| 30 |
* Constructor |
| 31 |
* |
| 32 |
* @since 3.4.7 |
| 33 |
* |
| 34 |
* @param object $base Base Plugin Class. |
| 35 |
*/ |
| 36 |
public function __construct( $base ) { |
| 37 |
|
| 38 |
// Store base class. |
| 39 |
$this->base = $base; |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Helper method to retrieve status post type options |
| 45 |
* |
| 46 |
* @since 6.0.0 |
| 47 |
* |
| 48 |
* @return array Status Post Type Options |
| 49 |
*/ |
| 50 |
public function get_status_post_type_options() { |
| 51 |
|
| 52 |
// Build status post type options. |
| 53 |
$status_post_type_options = array( |
| 54 |
'text' => __( 'Text', 'wp-to-buffer' ), |
| 55 |
'link' => __( 'Link', 'wp-to-buffer' ), |
| 56 |
'image' => __( 'Image', 'wp-to-buffer' ), |
| 57 |
); |
| 58 |
|
| 59 |
/** |
| 60 |
* Defines the available status post type options. |
| 61 |
* |
| 62 |
* @since 6.0.0 |
| 63 |
* |
| 64 |
* @param array $status_post_type_options Status Post Type Options. |
| 65 |
*/ |
| 66 |
$status_post_type_options = apply_filters( $this->base->plugin->filter_name . '_get_status_post_type_options', $status_post_type_options ); |
| 67 |
|
| 68 |
// Return filtered results. |
| 69 |
return $status_post_type_options; |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Helper method to retrieve schedule options |
| 75 |
* |
| 76 |
* @since 3.0.0 |
| 77 |
* |
| 78 |
* @param mixed $post_type Post Type (false | string). |
| 79 |
* @param bool $is_post_screen Displaying the Post Screen. |
| 80 |
* @return array Schedule Options |
| 81 |
*/ |
| 82 |
public function get_schedule_options( $post_type = false, $is_post_screen = false ) { |
| 83 |
|
| 84 |
// Immediate posting is supported by every service, so it is always available. |
| 85 |
$schedule = array( |
| 86 |
'immediate' => __( 'Post Immediately', 'wp-to-buffer' ), |
| 87 |
); |
| 88 |
|
| 89 |
/** |
| 90 |
* Defines the available schedule options for each individual status. |
| 91 |
* |
| 92 |
* @since 3.0.0 |
| 93 |
* |
| 94 |
* @param array $schedule Schedule Options. |
| 95 |
* @param string $post_type Post Type. |
| 96 |
* @param bool $is_post_screen On Post Edit Screen. |
| 97 |
*/ |
| 98 |
$schedule = apply_filters( $this->base->plugin->filter_name . '_get_schedule_options', $schedule, $post_type, $is_post_screen ); |
| 99 |
|
| 100 |
// Return filtered results. |
| 101 |
return $schedule; |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Helper method to retrieve Google Business Start Date options |
| 107 |
* |
| 108 |
* @since 4.9.0 |
| 109 |
* |
| 110 |
* @param mixed $post_type Post Type (false | string). |
| 111 |
* @return array Start Date Options |
| 112 |
*/ |
| 113 |
public function get_google_business_start_date_options( $post_type = false ) { |
| 114 |
|
| 115 |
// Build schedule options. |
| 116 |
$schedule = array( |
| 117 |
'custom' => __( 'Custom Field / Post Meta Value', 'wp-to-buffer' ), |
| 118 |
); |
| 119 |
|
| 120 |
/** |
| 121 |
* Defines the available start date options for a Google Business Profile status. |
| 122 |
* |
| 123 |
* @since 4.9.0 |
| 124 |
* |
| 125 |
* @param array $schedule Schedule Options. |
| 126 |
*/ |
| 127 |
$schedule = apply_filters( $this->base->plugin->filter_name . '_get_google_business_start_date_options', $schedule, $post_type ); |
| 128 |
|
| 129 |
// Return filtered results. |
| 130 |
return $schedule; |
| 131 |
|
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Helper method to retrieve Google Business Start Date options |
| 136 |
* |
| 137 |
* @since 4.9.0 |
| 138 |
* |
| 139 |
* @param mixed $post_type Post Type (false | string). |
| 140 |
* @return array End Date Options |
| 141 |
*/ |
| 142 |
public function get_google_business_end_date_options( $post_type = false ) { |
| 143 |
|
| 144 |
// Build schedule options. |
| 145 |
$schedule = array( |
| 146 |
'custom' => __( 'Custom Field / Post Meta Value', 'wp-to-buffer' ), |
| 147 |
); |
| 148 |
|
| 149 |
/** |
| 150 |
* Defines the available start date options for a Google Business Profile status. |
| 151 |
* |
| 152 |
* @since 4.9.0 |
| 153 |
* |
| 154 |
* @param array $schedule Schedule Options. |
| 155 |
*/ |
| 156 |
$schedule = apply_filters( $this->base->plugin->filter_name . '_get_google_business_end_date_options', $schedule, $post_type ); |
| 157 |
|
| 158 |
// Return filtered results. |
| 159 |
return $schedule; |
| 160 |
|
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* Helper method to retrieve public Post Types |
| 165 |
* |
| 166 |
* @since 3.0.0 |
| 167 |
* |
| 168 |
* @return array Public Post Types |
| 169 |
*/ |
| 170 |
public function get_post_types() { |
| 171 |
|
| 172 |
// Get public Post Types. |
| 173 |
$types = get_post_types( |
| 174 |
array( |
| 175 |
'public' => true, |
| 176 |
), |
| 177 |
'objects' |
| 178 |
); |
| 179 |
|
| 180 |
// Filter out excluded post types. |
| 181 |
$excluded_types = $this->get_excluded_post_types(); |
| 182 |
if ( is_array( $excluded_types ) ) { |
| 183 |
foreach ( $excluded_types as $excluded_type ) { |
| 184 |
unset( $types[ $excluded_type ] ); |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* Defines the available Post Type Objects that can have statues defined and be sent to social media. |
| 190 |
* |
| 191 |
* @since 3.0.0 |
| 192 |
* |
| 193 |
* @param array $types Post Types. |
| 194 |
*/ |
| 195 |
$types = apply_filters( $this->base->plugin->filter_name . '_get_post_types', $types ); |
| 196 |
|
| 197 |
// Return filtered results. |
| 198 |
return $types; |
| 199 |
|
| 200 |
} |
| 201 |
|
| 202 |
/** |
| 203 |
* Helper method to retrieve excluded Post Types, which should not send |
| 204 |
* statuses to the API |
| 205 |
* |
| 206 |
* @since 3.0.0 |
| 207 |
* |
| 208 |
* @return array Excluded Post Types |
| 209 |
*/ |
| 210 |
public function get_excluded_post_types() { |
| 211 |
|
| 212 |
// Get excluded Post Types. |
| 213 |
$types = array( |
| 214 |
'attachment', |
| 215 |
'revision', |
| 216 |
'elementor_library', |
| 217 |
); |
| 218 |
|
| 219 |
/** |
| 220 |
* Defines the Post Type Objects that cannot have statues defined and not be sent to social media. |
| 221 |
* |
| 222 |
* @since 3.0.0 |
| 223 |
* |
| 224 |
* @param array $types Post Types. |
| 225 |
*/ |
| 226 |
$types = apply_filters( $this->base->plugin->filter_name . '_get_excluded_post_types', $types ); |
| 227 |
|
| 228 |
// Return filtered results. |
| 229 |
return $types; |
| 230 |
|
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* Helper method to retrieve excluded Taxonomies |
| 235 |
* |
| 236 |
* @since 3.0.5 |
| 237 |
* |
| 238 |
* @return array Excluded Post Types |
| 239 |
*/ |
| 240 |
public function get_excluded_taxonomies() { |
| 241 |
|
| 242 |
// Get excluded Post Types. |
| 243 |
$taxonomies = array( |
| 244 |
'post_format', |
| 245 |
'nav_menu', |
| 246 |
); |
| 247 |
|
| 248 |
/** |
| 249 |
* Defines taxonomies to exclude from the Conditions: Taxonomies dropdowns for each individual status. |
| 250 |
* |
| 251 |
* @since 3.0.5 |
| 252 |
* |
| 253 |
* @param array $taxonomies Excluded Taxonomies. |
| 254 |
*/ |
| 255 |
$taxonomies = apply_filters( $this->base->plugin->filter_name . '_get_excluded_taxonomies', $taxonomies ); |
| 256 |
|
| 257 |
// Return filtered results. |
| 258 |
return $taxonomies; |
| 259 |
|
| 260 |
} |
| 261 |
|
| 262 |
/** |
| 263 |
* Helper method to retrieve a Post Type's taxonomies |
| 264 |
* |
| 265 |
* @since 3.0.0 |
| 266 |
* |
| 267 |
* @param string $post_type Post Type. |
| 268 |
* @return array Taxonomies |
| 269 |
*/ |
| 270 |
public function get_taxonomies( $post_type ) { |
| 271 |
|
| 272 |
// Get Post Type Taxonomies. |
| 273 |
$taxonomies = get_object_taxonomies( $post_type, 'objects' ); |
| 274 |
|
| 275 |
// Get excluded Taxonomies. |
| 276 |
$excluded_taxonomies = $this->get_excluded_taxonomies(); |
| 277 |
|
| 278 |
// If excluded taxonomies exist, remove them from the taxonomies array now. |
| 279 |
if ( is_array( $excluded_taxonomies ) && count( $excluded_taxonomies ) > 0 ) { |
| 280 |
foreach ( $excluded_taxonomies as $excluded_taxonomy ) { |
| 281 |
unset( $taxonomies[ $excluded_taxonomy ] ); |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
/** |
| 286 |
* Defines available taxonomies for the given Post Type, which are used in the Conditions: Taxonomies dropdowns |
| 287 |
* for each individual status. |
| 288 |
* |
| 289 |
* @since 3.0.0 |
| 290 |
* |
| 291 |
* @param array $taxonomies Taxonomies. |
| 292 |
* @param string $post_type Post Type. |
| 293 |
*/ |
| 294 |
$taxonomies = apply_filters( $this->base->plugin->filter_name . '_get_taxonomies', $taxonomies, $post_type ); |
| 295 |
|
| 296 |
// Return filtered results. |
| 297 |
return $taxonomies; |
| 298 |
|
| 299 |
} |
| 300 |
|
| 301 |
/** |
| 302 |
* Helper method to retrieve all taxonomies |
| 303 |
* |
| 304 |
* @since 3.6.7 |
| 305 |
* |
| 306 |
* @return array Taxonomies |
| 307 |
*/ |
| 308 |
public function get_all_taxonomies() { |
| 309 |
|
| 310 |
// Get Post Type Taxonomies. |
| 311 |
$taxonomies = get_taxonomies( false, 'objects' ); |
| 312 |
|
| 313 |
// Get excluded Taxonomies. |
| 314 |
$excluded_taxonomies = $this->get_excluded_taxonomies(); |
| 315 |
|
| 316 |
// If excluded taxonomies exist, remove them from the taxonomies array now. |
| 317 |
if ( is_array( $excluded_taxonomies ) && count( $excluded_taxonomies ) > 0 ) { |
| 318 |
foreach ( $excluded_taxonomies as $excluded_taxonomy ) { |
| 319 |
unset( $taxonomies[ $excluded_taxonomy ] ); |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
/** |
| 324 |
* Defines available taxonomies, regardless of Post Type, which are used in the Conditions: Taxonomies dropdowns |
| 325 |
* for each individual status. |
| 326 |
* |
| 327 |
* @since 3.6.7 |
| 328 |
* |
| 329 |
* @param array $taxonomies Taxonomies. |
| 330 |
*/ |
| 331 |
$taxonomies = apply_filters( $this->base->plugin->filter_name . '_get_all_taxonomies', $taxonomies ); |
| 332 |
|
| 333 |
// Return filtered results. |
| 334 |
return $taxonomies; |
| 335 |
|
| 336 |
} |
| 337 |
|
| 338 |
/** |
| 339 |
* Helper method to retrieve available tags for status updates |
| 340 |
* |
| 341 |
* @since 3.0.0 |
| 342 |
* |
| 343 |
* @param string $post_type Post Type. |
| 344 |
* @return array Tags |
| 345 |
*/ |
| 346 |
public function get_tags( $post_type ) { |
| 347 |
|
| 348 |
// Get post type. |
| 349 |
$post_types = $this->get_post_types(); |
| 350 |
|
| 351 |
// Build tags array. |
| 352 |
$tags = array( |
| 353 |
'post' => array( |
| 354 |
'{sitename}' => __( 'Site Name', 'wp-to-buffer' ), |
| 355 |
'{title}' => __( 'Post Title', 'wp-to-buffer' ), |
| 356 |
'{excerpt}' => __( 'Post Excerpt (Full)', 'wp-to-buffer' ), |
| 357 |
'{excerpt:characters(?)}' => array( |
| 358 |
'question' => __( 'Enter the maximum number of characters the Post Excerpt should display.', 'wp-to-buffer' ), |
| 359 |
'default_value' => '150', |
| 360 |
'replace' => '?', |
| 361 |
'label' => __( 'Post Excerpt (Character Limited)', 'wp-to-buffer' ), |
| 362 |
), |
| 363 |
'{excerpt:words(?)}' => array( |
| 364 |
'question' => __( 'Enter the maximum number of words the Post Excerpt should display.', 'wp-to-buffer' ), |
| 365 |
'default_value' => '55', |
| 366 |
'replace' => '?', |
| 367 |
'label' => __( 'Post Excerpt (Word Limited)', 'wp-to-buffer' ), |
| 368 |
), |
| 369 |
'{excerpt:sentences(?)}' => array( |
| 370 |
'question' => __( 'Enter the maximum number of sentences the Post Excerpt should display.', 'wp-to-buffer' ), |
| 371 |
'default_value' => '1', |
| 372 |
'replace' => '?', |
| 373 |
'label' => __( 'Post Excerpt (Sentence Limited)', 'wp-to-buffer' ), |
| 374 |
), |
| 375 |
'{content}' => __( 'Post Content (Full)', 'wp-to-buffer' ), |
| 376 |
'{content_more_tag}' => __( 'Post Content (Up to More Tag)', 'wp-to-buffer' ), |
| 377 |
'{content:characters(?)}' => array( |
| 378 |
'question' => __( 'Enter the maximum number of characters the Post Content should display.', 'wp-to-buffer' ), |
| 379 |
'default_value' => '150', |
| 380 |
'replace' => '?', |
| 381 |
'label' => __( 'Post Content (Character Limited)', 'wp-to-buffer' ), |
| 382 |
), |
| 383 |
'{content:words(?)}' => array( |
| 384 |
'question' => __( 'Enter the maximum number of words the Post Content should display.', 'wp-to-buffer' ), |
| 385 |
'default_value' => '55', |
| 386 |
'replace' => '?', |
| 387 |
'label' => __( 'Post Content (Word Limited)', 'wp-to-buffer' ), |
| 388 |
), |
| 389 |
'{content:sentences(?)}' => array( |
| 390 |
'question' => __( 'Enter the maximum number of sentences the Post Content should display.', 'wp-to-buffer' ), |
| 391 |
'default_value' => '1', |
| 392 |
'replace' => '?', |
| 393 |
'label' => __( 'Post Content (Sentence Limited)', 'wp-to-buffer' ), |
| 394 |
), |
| 395 |
'{date}' => __( 'Post Date', 'wp-to-buffer' ), |
| 396 |
'{url}' => __( 'Post URL', 'wp-to-buffer' ), |
| 397 |
'{url_short}' => __( 'Post URL, Shortened', 'wp-to-buffer' ), |
| 398 |
'{id}' => __( 'Post ID', 'wp-to-buffer' ), |
| 399 |
), |
| 400 |
); |
| 401 |
|
| 402 |
// Add any taxonomies for the given Post Type, if the Post Type exists. |
| 403 |
$taxonomies = array(); |
| 404 |
if ( isset( $post_types[ $post_type ] ) ) { |
| 405 |
// Get taxonomies specific to the Post Type. |
| 406 |
$taxonomies = $this->get_taxonomies( $post_type ); |
| 407 |
} else { |
| 408 |
// We're on the Bulk Publishing Settings, so return all Taxonomies. |
| 409 |
$taxonomies = $this->get_all_taxonomies(); |
| 410 |
} |
| 411 |
|
| 412 |
if ( count( $taxonomies ) > 0 ) { |
| 413 |
$tags['taxonomy'] = array(); |
| 414 |
|
| 415 |
foreach ( $taxonomies as $tax => $details ) { |
| 416 |
$tags['taxonomy'][ '{taxonomy_' . $tax . '}' ] = sprintf( |
| 417 |
/* translators: Taxonomy Name, Singular */ |
| 418 |
__( 'Taxonomy: %s: Hashtag Format', 'wp-to-buffer' ), |
| 419 |
$details->labels->singular_name |
| 420 |
); |
| 421 |
} |
| 422 |
} |
| 423 |
|
| 424 |
/** |
| 425 |
* Defines Dynamic Status Tags that can be inserted into status(es) for the given Post Type. |
| 426 |
* These tags are also added to any 'Insert Tag' dropdowns. |
| 427 |
* |
| 428 |
* @since 3.0.0 |
| 429 |
* |
| 430 |
* @param array $tags Dynamic Status Tags. |
| 431 |
* @param string $post_type Post Type. |
| 432 |
*/ |
| 433 |
$tags = apply_filters( $this->base->plugin->filter_name . '_get_tags', $tags, $post_type ); |
| 434 |
|
| 435 |
// Return filtered results. |
| 436 |
return $tags; |
| 437 |
|
| 438 |
} |
| 439 |
|
| 440 |
/** |
| 441 |
* Helper method to retrieve available tags for status updates, in a flattened |
| 442 |
* key/value array |
| 443 |
* |
| 444 |
* @since 4.5.7 |
| 445 |
* |
| 446 |
* @param string $post_type Post Type. |
| 447 |
* @return array Tags |
| 448 |
*/ |
| 449 |
public function get_tags_flat( $post_type ) { |
| 450 |
|
| 451 |
$tags_flat = array(); |
| 452 |
foreach ( $this->get_tags( $post_type ) as $tag_group => $tag_group_tags ) { |
| 453 |
foreach ( $tag_group_tags as $tag => $tag_attributes ) { |
| 454 |
$tags_flat[] = array( |
| 455 |
'key' => $tag, |
| 456 |
'value' => $tag, |
| 457 |
); |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
return $tags_flat; |
| 462 |
|
| 463 |
} |
| 464 |
|
| 465 |
/** |
| 466 |
* Helper method to retrieve Post actions |
| 467 |
* |
| 468 |
* @since 3.0.0 |
| 469 |
* |
| 470 |
* @return array Post Actions |
| 471 |
*/ |
| 472 |
public function get_post_actions() { |
| 473 |
|
| 474 |
// Build post actions. |
| 475 |
$actions = array( |
| 476 |
'publish' => __( 'Publish', 'wp-to-buffer' ), |
| 477 |
'update' => __( 'Update', 'wp-to-buffer' ), |
| 478 |
); |
| 479 |
|
| 480 |
/** |
| 481 |
* Defines the Post actions which trigger status(es) to be sent to social media. |
| 482 |
* |
| 483 |
* @since 3.0.0 |
| 484 |
* |
| 485 |
* @param array $actions Post Actions. |
| 486 |
*/ |
| 487 |
$actions = apply_filters( $this->base->plugin->filter_name . '_get_post_actions', $actions ); |
| 488 |
|
| 489 |
// Return filtered results. |
| 490 |
return $actions; |
| 491 |
|
| 492 |
} |
| 493 |
|
| 494 |
/** |
| 495 |
* Helper method to retrieve Post actions, with labels in the past tense. |
| 496 |
* |
| 497 |
* @since 3.7.2 |
| 498 |
* |
| 499 |
* @return array Post Actions |
| 500 |
*/ |
| 501 |
public function get_post_actions_past_tense() { |
| 502 |
|
| 503 |
// Build post actions. |
| 504 |
$actions = array( |
| 505 |
'publish' => __( 'Published', 'wp-to-buffer' ), |
| 506 |
'update' => __( 'Updated', 'wp-to-buffer' ), |
| 507 |
); |
| 508 |
|
| 509 |
/** |
| 510 |
* Defines the Post actions which trigger status(es) to be sent to social media, |
| 511 |
* with labels set to the past tense. |
| 512 |
* |
| 513 |
* @since 3.0.0 |
| 514 |
* |
| 515 |
* @param array $actions Post Actions. |
| 516 |
*/ |
| 517 |
$actions = apply_filters( $this->base->plugin->filter_name . '_get_post_actions_past_tense', $actions ); |
| 518 |
|
| 519 |
// Return filtered results. |
| 520 |
return $actions; |
| 521 |
|
| 522 |
} |
| 523 |
|
| 524 |
/** |
| 525 |
* Helper method to return template tags that cannot have a character limit applied to them. |
| 526 |
* |
| 527 |
* @since 3.7.8 |
| 528 |
* |
| 529 |
* @return array Tags. |
| 530 |
*/ |
| 531 |
public function get_tags_excluded_from_character_limit() { |
| 532 |
|
| 533 |
$tags = array( |
| 534 |
'date', |
| 535 |
'url', |
| 536 |
'id', |
| 537 |
'author_user_email', |
| 538 |
'author_user_url', |
| 539 |
); |
| 540 |
|
| 541 |
/** |
| 542 |
* Defines the tags that cannot have a character limit applied to them, as doing so would |
| 543 |
* wrongly concatenate data (e.g. a URL would become malformed). |
| 544 |
* |
| 545 |
* @since 3.7.8 |
| 546 |
* |
| 547 |
* @param array $tags Tags. |
| 548 |
*/ |
| 549 |
$tags = apply_filters( $this->base->plugin->filter_name . '_get_tags_excluded_from_character_limit', $tags ); |
| 550 |
|
| 551 |
// Return filtered results. |
| 552 |
return $tags; |
| 553 |
|
| 554 |
} |
| 555 |
|
| 556 |
/** |
| 557 |
* Helper method to retrieve transient expiration time |
| 558 |
* |
| 559 |
* @since 3.0.0 |
| 560 |
* |
| 561 |
* @return int Expiration Time (seconds) |
| 562 |
*/ |
| 563 |
public function get_transient_expiration_time() { |
| 564 |
|
| 565 |
// Set expiration time for all transients = 1 week. |
| 566 |
$expiration_time = ( 7 * DAY_IN_SECONDS ); |
| 567 |
|
| 568 |
/** |
| 569 |
* Defines the number of seconds before expiring transients. |
| 570 |
* |
| 571 |
* @since 3.0.0 |
| 572 |
* |
| 573 |
* @param int $expiration_time Transient Expiration Time, in seconds. |
| 574 |
*/ |
| 575 |
$expiration_time = apply_filters( $this->base->plugin->filter_name . '_get_transient_expiration_time', $expiration_time ); |
| 576 |
|
| 577 |
// Return filtered results. |
| 578 |
return $expiration_time; |
| 579 |
|
| 580 |
} |
| 581 |
|
| 582 |
/** |
| 583 |
* Defines the registered filters that can be used on the Log WP_List_Table |
| 584 |
* |
| 585 |
* @since 3.9.8 |
| 586 |
* |
| 587 |
* @return array Filters |
| 588 |
*/ |
| 589 |
public function get_log_filters() { |
| 590 |
|
| 591 |
// Define filters. |
| 592 |
$filters = array( |
| 593 |
'action', |
| 594 |
'profile_id', |
| 595 |
'result', |
| 596 |
'request_sent_start_date', |
| 597 |
'request_sent_end_date', |
| 598 |
'orderby', |
| 599 |
'order', |
| 600 |
); |
| 601 |
|
| 602 |
/** |
| 603 |
* Defines the registered filters that can be used on the Log WP_List_Tables. |
| 604 |
* |
| 605 |
* @since 3.9.8 |
| 606 |
* |
| 607 |
* @param array $filters Filters. |
| 608 |
*/ |
| 609 |
$filters = apply_filters( $this->base->plugin->filter_name . '_get_log_filters', $filters ); |
| 610 |
|
| 611 |
// Return filtered results. |
| 612 |
return $filters; |
| 613 |
|
| 614 |
} |
| 615 |
|
| 616 |
/** |
| 617 |
* Helper method to check if the collation of the given table is correct |
| 618 |
* |
| 619 |
* @since 5.5.5 |
| 620 |
* |
| 621 |
* @param string $table_name Table Name. |
| 622 |
* @param string $required_collation Required Collation. |
| 623 |
* @return bool |
| 624 |
*/ |
| 625 |
public function is_table_charset_and_collation_correct( $table_name = 'options', $required_collation = 'utf8mb4' ) { |
| 626 |
|
| 627 |
global $wpdb; |
| 628 |
|
| 629 |
$result = $wpdb->get_row( |
| 630 |
"SHOW CREATE TABLE `{$wpdb->{$table_name}}`", |
| 631 |
ARRAY_A |
| 632 |
); |
| 633 |
|
| 634 |
// If no result, return true, as we can't reliably tell if the collation is correct. |
| 635 |
if ( ! array_key_exists( 'Create Table', $result ) || empty( $result['Create Table'] ) ) { |
| 636 |
return true; |
| 637 |
} |
| 638 |
|
| 639 |
// Extract the default charset and collation from the create table SQL. |
| 640 |
preg_match( '/DEFAULT CHARSET=([a-zA-Z0-9_]+)/i', $result['Create Table'], $default_charset ); |
| 641 |
preg_match( '/COLLATE=([a-zA-Z0-9_]+)/i', $result['Create Table'], $default_collation ); |
| 642 |
|
| 643 |
if ( strpos( $default_charset[1], $required_collation ) === false ) { |
| 644 |
return false; |
| 645 |
} |
| 646 |
if ( strpos( $default_collation[1], $required_collation ) === false ) { |
| 647 |
return false; |
| 648 |
} |
| 649 |
|
| 650 |
return true; |
| 651 |
|
| 652 |
} |
| 653 |
|
| 654 |
} |
| 655 |
|