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