Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Publicize_Base often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Publicize_Base, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 5 | abstract class Publicize_Base { |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Services that are currently connected to the given user |
||
| 9 | * through publicize. |
||
| 10 | */ |
||
| 11 | public $connected_services = array(); |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Services that are supported by publicize. They don't |
||
| 15 | * necessarily need to be connected to the current user. |
||
| 16 | */ |
||
| 17 | public $services; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * key names for post meta |
||
| 21 | */ |
||
| 22 | public $ADMIN_PAGE = 'wpas'; |
||
| 23 | public $POST_MESS = '_wpas_mess'; |
||
| 24 | public $POST_SKIP = '_wpas_skip_'; // connection id appended to indicate that a connection should NOT be publicized to |
||
| 25 | public $POST_DONE = '_wpas_done_'; // connection id appended to indicate a connection has already been publicized to |
||
| 26 | public $USER_AUTH = 'wpas_authorize'; |
||
| 27 | public $USER_OPT = 'wpas_'; |
||
| 28 | public $PENDING = '_publicize_pending'; // ready for Publicize to do its thing |
||
| 29 | public $POST_SERVICE_DONE = '_publicize_done_external'; // array of external ids where we've Publicized |
||
| 30 | |||
| 31 | /** |
||
| 32 | * default pieces of the message used in constructing the |
||
| 33 | * content pushed out to other social networks |
||
| 34 | */ |
||
| 35 | |||
| 36 | public $default_prefix = ''; |
||
| 37 | public $default_message = '%title%'; |
||
| 38 | public $default_suffix = ' '; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * What WP capability is require to create/delete global connections? |
||
| 42 | * All users with this cap can un-globalize all other global connections, and globalize any of their own |
||
| 43 | * Globalized connections cannot be unselected by users without this capability when publishing |
||
| 44 | */ |
||
| 45 | public $GLOBAL_CAP = 'publish_posts'; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Sets up the basics of Publicize |
||
| 49 | */ |
||
| 50 | function __construct() { |
||
| 51 | $this->default_message = self::build_sprintf( array( |
||
| 52 | /** |
||
| 53 | * Filter the default Publicize message. |
||
| 54 | * |
||
| 55 | * @module publicize |
||
| 56 | * |
||
| 57 | * @since 2.0.0 |
||
| 58 | * |
||
| 59 | * @param string $this->default_message Publicize's default message. Default is the post title. |
||
| 60 | */ |
||
| 61 | apply_filters( 'wpas_default_message', $this->default_message ), |
||
| 62 | 'title', |
||
| 63 | 'url', |
||
| 64 | ) ); |
||
| 65 | |||
| 66 | $this->default_prefix = self::build_sprintf( array( |
||
| 67 | /** |
||
| 68 | * Filter the message prepended to the Publicize custom message. |
||
| 69 | * |
||
| 70 | * @module publicize |
||
| 71 | * |
||
| 72 | * @since 2.0.0 |
||
| 73 | * |
||
| 74 | * @param string $this->default_prefix String prepended to the Publicize custom message. |
||
| 75 | */ |
||
| 76 | apply_filters( 'wpas_default_prefix', $this->default_prefix ), |
||
| 77 | 'url', |
||
| 78 | ) ); |
||
| 79 | |||
| 80 | $this->default_suffix = self::build_sprintf( array( |
||
| 81 | /** |
||
| 82 | * Filter the message appended to the Publicize custom message. |
||
| 83 | * |
||
| 84 | * @module publicize |
||
| 85 | * |
||
| 86 | * @since 2.0.0 |
||
| 87 | * |
||
| 88 | * @param string $this->default_suffix String appended to the Publicize custom message. |
||
| 89 | */ |
||
| 90 | apply_filters( 'wpas_default_suffix', $this->default_suffix ), |
||
| 91 | 'url', |
||
| 92 | ) ); |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Filter the capability to change global Publicize connection options. |
||
| 96 | * |
||
| 97 | * All users with this cap can un-globalize all other global connections, and globalize any of their own |
||
| 98 | * Globalized connections cannot be unselected by users without this capability when publishing. |
||
| 99 | * |
||
| 100 | * @module publicize |
||
| 101 | * |
||
| 102 | * @since 2.2.1 |
||
| 103 | * |
||
| 104 | * @param string $this->GLOBAL_CAP default capability in control of global Publicize connection options. Default to edit_others_posts. |
||
| 105 | */ |
||
| 106 | $this->GLOBAL_CAP = apply_filters( 'jetpack_publicize_global_connections_cap', $this->GLOBAL_CAP ); |
||
| 107 | |||
| 108 | // stage 1 and 2 of 3-stage Publicize. Flag for Publicize on creation, save meta, |
||
| 109 | // then check meta and publicize based on that. stage 3 implemented on wpcom |
||
| 110 | add_action( 'transition_post_status', array( $this, 'flag_post_for_publicize' ), 10, 3 ); |
||
| 111 | add_action( 'save_post', array( &$this, 'save_meta' ), 20, 2 ); |
||
| 112 | |||
| 113 | // Default checkbox state for each Connection |
||
| 114 | add_filter( 'publicize_checkbox_default', array( $this, 'publicize_checkbox_default' ), 10, 4 ); |
||
| 115 | |||
| 116 | // Alter the "Post Publish" admin notice to mention the Connections we Publicized to. |
||
| 117 | add_filter( 'post_updated_messages', array( $this, 'update_published_message' ), 20, 1 ); |
||
| 118 | |||
| 119 | // Connection test callback |
||
| 120 | add_action( 'wp_ajax_test_publicize_conns', array( $this, 'test_publicize_conns' ) ); |
||
| 121 | |||
| 122 | add_action( 'init', array( $this, 'add_post_type_support' ) ); |
||
| 123 | add_action( 'init', array( $this, 'register_post_meta' ), 20 ); |
||
| 124 | add_action( 'jetpack_register_gutenberg_extensions', array( $this, 'register_gutenberg_extension' ) ); |
||
| 125 | } |
||
| 126 | |||
| 127 | /* |
||
| 128 | * Services: Facebook, Twitter, etc. |
||
| 129 | */ |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Get services for the given blog and user. |
||
| 133 | * |
||
| 134 | * Can return all available services or just the ones with an active connection. |
||
| 135 | * |
||
| 136 | * @param string $filter |
||
| 137 | * 'all' (default) - Get all services available for connecting |
||
| 138 | * 'connected' - Get all services currently connected |
||
| 139 | * @param false|int $_blog_id The blog ID. Use false (default) for the current blog |
||
| 140 | * @param false|int $_user_id The user ID. Use false (default) for the current user |
||
| 141 | * @return array |
||
| 142 | */ |
||
| 143 | abstract function get_services( $filter = 'all', $_blog_id = false, $_user_id = false ); |
||
| 144 | |||
| 145 | function can_connect_service( $service_name ) { |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Does the given user have a connection to the service on the given blog? |
||
| 151 | * |
||
| 152 | * @param string $service_name 'facebook', 'twitter', etc. |
||
| 153 | * @param false|int $_blog_id The blog ID. Use false (default) for the current blog |
||
| 154 | * @param false|int $_user_id The user ID. Use false (default) for the current user |
||
| 155 | * @return bool |
||
| 156 | */ |
||
| 157 | function is_enabled( $service_name, $_blog_id = false, $_user_id = false ) { |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Generates a connection URL. |
||
| 170 | * |
||
| 171 | * This is the URL, which, when visited by the user, starts the authentication |
||
| 172 | * process required to forge a connection. |
||
| 173 | * |
||
| 174 | * @param string $service_name 'facebook', 'twitter', etc. |
||
| 175 | * @return string |
||
| 176 | */ |
||
| 177 | abstract function connect_url( $service_name ); |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Generates a Connection refresh URL. |
||
| 181 | * |
||
| 182 | * This is the URL, which, when visited by the user, re-authenticates their |
||
| 183 | * connection to the service. |
||
| 184 | * |
||
| 185 | * @param string $service_name 'facebook', 'twitter', etc. |
||
| 186 | * @return string |
||
| 187 | */ |
||
| 188 | abstract function refresh_url( $service_name ); |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Generates a disconnection URL. |
||
| 192 | * |
||
| 193 | * This is the URL, which, when visited by the user, breaks their connection |
||
| 194 | * with the service. |
||
| 195 | * |
||
| 196 | * @param string $service_name 'facebook', 'twitter', etc. |
||
| 197 | * @param string $connection_id Connection ID |
||
| 198 | * @return string |
||
| 199 | */ |
||
| 200 | abstract function disconnect_url( $service_name, $connection_id ); |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Returns a display name for the Service |
||
| 204 | * |
||
| 205 | * @param string $service_name 'facebook', 'twitter', etc. |
||
| 206 | * @return string |
||
| 207 | */ |
||
| 208 | public static function get_service_label( $service_name ) { |
||
| 225 | |||
| 226 | /* |
||
| 227 | * Connections: For each Service, there can be multiple connections |
||
| 228 | * for a given user. For example, one user could be connected to Twitter |
||
| 229 | * as both @jetpack and as @wordpressdotcom |
||
| 230 | * |
||
| 231 | * For historical reasons, Connections are represented as an object |
||
| 232 | * on WordPress.com and as an array in Jetpack. |
||
| 233 | */ |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Get the active Connections of a Service |
||
| 237 | * |
||
| 238 | * @param string $service_name 'facebook', 'twitter', etc. |
||
| 239 | * @param false|int $_blog_id The blog ID. Use false (default) for the current blog |
||
| 240 | * @param false|int $_user_id The user ID. Use false (default) for the current user |
||
| 241 | * @return false|object[]|array[] false if no connections exist |
||
| 242 | */ |
||
| 243 | abstract function get_connections( $service_name, $_blog_id = false, $_user_id = false ); |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Get a single Connection of a Service |
||
| 247 | * |
||
| 248 | * @param string $service_name 'facebook', 'twitter', etc. |
||
| 249 | * @param string $connection_id Connection ID |
||
| 250 | * @param false|int $_blog_id The blog ID. Use false (default) for the current blog |
||
| 251 | * @param false|int $_user_id The user ID. Use false (default) for the current user |
||
| 252 | * @return false|object[]|array[] false if no connections exist |
||
| 253 | */ |
||
| 254 | abstract function get_connection( $service_name, $connection_id, $_blog_id = false, $_user_id = false ); |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Get the Connection ID. |
||
| 258 | * |
||
| 259 | * Note that this is different than the Connection's uniqueid. |
||
| 260 | * |
||
| 261 | * Via a quirk of history, ID is globally unique and unique_id |
||
| 262 | * is only unique per site. |
||
| 263 | * |
||
| 264 | * @param object|array The Connection object (WordPress.com) or array (Jetpack) |
||
| 265 | * @return string |
||
| 266 | */ |
||
| 267 | abstract function get_connection_id( $connection ); |
||
| 268 | |||
| 269 | /** |
||
| 270 | * Get the Connection unique_id |
||
| 271 | * |
||
| 272 | * Note that this is different than the Connections ID. |
||
| 273 | * |
||
| 274 | * Via a quirk of history, ID is globally unique and unique_id |
||
| 275 | * is only unique per site. |
||
| 276 | * |
||
| 277 | * @param object|array The Connection object (WordPress.com) or array (Jetpack) |
||
| 278 | * @return string |
||
| 279 | */ |
||
| 280 | abstract function get_connection_unique_id( $connection ); |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Get the Connection's Meta data |
||
| 284 | * |
||
| 285 | * @param object|array Connection |
||
| 286 | * @return array Connection Meta |
||
| 287 | */ |
||
| 288 | abstract function get_connection_meta( $connection ); |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Disconnect a Connection |
||
| 292 | * |
||
| 293 | * @param string $service_name 'facebook', 'twitter', etc. |
||
| 294 | * @param string $connection_id Connection ID |
||
| 295 | * @param false|int $_blog_id The blog ID. Use false (default) for the current blog |
||
| 296 | * @param false|int $_user_id The user ID. Use false (default) for the current user |
||
| 297 | * @param bool $force_delete Whether to skip permissions checks |
||
| 298 | * @return false|void False on failure. Void on success. |
||
| 299 | */ |
||
| 300 | abstract function disconnect( $service_name, $connection_id, $_blog_id = false, $_user_id = false, $force_delete = false ); |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Globalizes a Connection |
||
| 304 | * |
||
| 305 | * @param string $connection_id Connection ID |
||
| 306 | * @return bool Falsey on failure. Truthy on success. |
||
| 307 | */ |
||
| 308 | abstract function globalize_connection( $connection_id ); |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Unglobalizes a Connection |
||
| 312 | * |
||
| 313 | * @param string $connection_id Connection ID |
||
| 314 | * @return bool Falsey on failure. Truthy on success. |
||
| 315 | */ |
||
| 316 | abstract function unglobalize_connection( $connection_id ); |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Returns an external URL to the Connection's profile |
||
| 320 | * |
||
| 321 | * @param string $service_name 'facebook', 'twitter', etc. |
||
| 322 | * @param object|array The Connection object (WordPress.com) or array (Jetpack) |
||
| 323 | * @return false|string False on failure. URL on success. |
||
| 324 | */ |
||
| 325 | function get_profile_link( $service_name, $connection ) { |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Returns a display name for the Connection |
||
| 364 | * |
||
| 365 | * @param string $service_name 'facebook', 'twitter', etc. |
||
| 366 | * @param object|array The Connection object (WordPress.com) or array (Jetpack) |
||
| 367 | * @return string |
||
| 368 | */ |
||
| 369 | function get_display_name( $service_name, $connection ) { |
||
| 385 | |||
| 386 | /** |
||
| 387 | * Whether the user needs to select additional options after connecting |
||
| 388 | * |
||
| 389 | * @param string $service_name 'facebook', 'twitter', etc. |
||
| 390 | * @param object|array The Connection object (WordPress.com) or array (Jetpack) |
||
| 391 | * @return bool |
||
| 392 | */ |
||
| 393 | function show_options_popup( $service_name, $connection ) { |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Whether the Connection is "valid" wrt Facebook's requirements. |
||
| 419 | * |
||
| 420 | * Must be connected to a Page (not a Profile). |
||
| 421 | * (Also returns true if we're in the middle of the connection process) |
||
| 422 | * |
||
| 423 | * @param object|array The Connection object (WordPress.com) or array (Jetpack) |
||
| 424 | * @return bool |
||
| 425 | */ |
||
| 426 | function is_valid_facebook_connection( $connection ) { |
||
| 434 | |||
| 435 | /** |
||
| 436 | * LinkedIn needs to be reauthenticated to use v2 of their API. |
||
| 437 | * If it's using LinkedIn old API, it's an 'invalid' connection |
||
| 438 | * |
||
| 439 | * @param object|array The Connection object (WordPress.com) or array (Jetpack) |
||
| 440 | * @return bool |
||
| 441 | */ |
||
| 442 | function is_invalid_linkedin_connection( $connection ) { |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Whether the Connection currently being connected |
||
| 450 | * |
||
| 451 | * @param object|array The Connection object (WordPress.com) or array (Jetpack) |
||
| 452 | * @return bool |
||
| 453 | */ |
||
| 454 | function is_connecting_connection( $connection ) { |
||
| 459 | |||
| 460 | /** |
||
| 461 | * AJAX Handler to run connection tests on all Connections |
||
| 462 | * @return void |
||
| 463 | */ |
||
| 464 | function test_publicize_conns() { |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Run connection tests on all Connections |
||
| 470 | * |
||
| 471 | * @return array { |
||
| 472 | * Array of connection test results. |
||
| 473 | * |
||
| 474 | * @type string 'connectionID' Connection identifier string that is unique for each connection |
||
| 475 | * @type string 'serviceName' Slug of the connection's service (facebook, twitter, ...) |
||
| 476 | * @type bool 'connectionTestPassed' Whether the connection test was successful |
||
| 477 | * @type string 'connectionTestMessage' Test success or error message |
||
| 478 | * @type bool 'userCanRefresh' Whether the user can re-authenticate their connection to the service |
||
| 479 | * @type string 'refreshText' Message instructing user to re-authenticate their connection to the service |
||
| 480 | * @type string 'refreshURL' URL, which, when visited by the user, re-authenticates their connection to the service. |
||
| 481 | * @type string 'unique_id' ID string representing connection |
||
| 482 | * } |
||
| 483 | */ |
||
| 484 | function get_publicize_conns_test_results() { |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Run the connection test for the Connection |
||
| 553 | * |
||
| 554 | * @param string $service_name 'facebook', 'twitter', etc. |
||
| 555 | * @param object|array The Connection object (WordPress.com) or array (Jetpack) |
||
| 556 | * @return WP_Error|true WP_Error on failure. True on success |
||
| 557 | */ |
||
| 558 | abstract function test_connection( $service_name, $connection ); |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Retrieves current list of connections and applies filters. |
||
| 562 | * |
||
| 563 | * Retrieves current available connections and checks if the connections |
||
| 564 | * have already been used to share current post. Finally, the checkbox |
||
| 565 | * form UI fields are calculated. This function exposes connection form |
||
| 566 | * data directly as array so it can be retrieved for static HTML generation |
||
| 567 | * or JSON consumption. |
||
| 568 | * |
||
| 569 | * @since 6.7.0 |
||
| 570 | * |
||
| 571 | * @param integer $selected_post_id Optional. Post ID to query connection status for. |
||
| 572 | * |
||
| 573 | * @return array { |
||
| 574 | * Array of UI setup data for connection list form. |
||
| 575 | * |
||
| 576 | * @type string 'unique_id' ID string representing connection |
||
| 577 | * @type string 'service_name' Slug of the connection's service (facebook, twitter, ...) |
||
| 578 | * @type string 'service_label' Service Label (Facebook, Twitter, ...) |
||
| 579 | * @type string 'display_name' Connection's human-readable Username: "@jetpack" |
||
| 580 | * @type bool 'enabled' Default value for the connection (e.g., for a checkbox). |
||
| 581 | * @type bool 'done' Has this connection already been publicized to? |
||
| 582 | * @type bool 'toggleable' Is the user allowed to change the value for the connection? |
||
| 583 | * @type bool 'global' Is this connection a global one? |
||
| 584 | * } |
||
| 585 | */ |
||
| 586 | public function get_filtered_connection_data( $selected_post_id = null ) { |
||
| 721 | |||
| 722 | /** |
||
| 723 | * Checks if post has already been shared by Publicize in the past. |
||
| 724 | * |
||
| 725 | * @since 6.7.0 |
||
| 726 | * |
||
| 727 | * @param integer $post_id Optional. Post ID to query connection status for: will use current post if missing. |
||
| 728 | * |
||
| 729 | * @return bool True if post has already been shared by Publicize, false otherwise. |
||
| 730 | */ |
||
| 731 | abstract public function post_is_done_sharing( $post_id = null ); |
||
| 732 | |||
| 733 | /** |
||
| 734 | * Retrieves full list of available Publicize connection services. |
||
| 735 | * |
||
| 736 | * Retrieves current available publicize service connections |
||
| 737 | * with associated labels and URLs. |
||
| 738 | * |
||
| 739 | * @since 6.7.0 |
||
| 740 | * |
||
| 741 | * @return array { |
||
| 742 | * Array of UI service connection data for all services |
||
| 743 | * |
||
| 744 | * @type string 'name' Name of service. |
||
| 745 | * @type string 'label' Display label for service. |
||
| 746 | * @type string 'url' URL for adding connection to service. |
||
| 747 | * } |
||
| 748 | */ |
||
| 749 | function get_available_service_data() { |
||
| 763 | |||
| 764 | /* |
||
| 765 | * Site Data |
||
| 766 | */ |
||
| 767 | |||
| 768 | function user_id() { |
||
| 771 | |||
| 772 | function blog_id() { |
||
| 775 | |||
| 776 | /* |
||
| 777 | * Posts |
||
| 778 | */ |
||
| 779 | |||
| 780 | /** |
||
| 781 | * Checks old and new status to see if the post should be flagged as |
||
| 782 | * ready to Publicize. |
||
| 783 | * |
||
| 784 | * Attached to the `transition_post_status` filter. |
||
| 785 | * |
||
| 786 | * @param string $new_status |
||
| 787 | * @param string $old_status |
||
| 788 | * @param WP_Post $post |
||
| 789 | * @return void |
||
| 790 | */ |
||
| 791 | abstract function flag_post_for_publicize( $new_status, $old_status, $post ); |
||
| 792 | |||
| 793 | /** |
||
| 794 | * Ensures the Post internal post-type supports `publicize` |
||
| 795 | * |
||
| 796 | * This feature support flag is used by the REST API. |
||
| 797 | */ |
||
| 798 | function add_post_type_support() { |
||
| 801 | |||
| 802 | /** |
||
| 803 | * Register the Publicize Gutenberg extension |
||
| 804 | */ |
||
| 805 | function register_gutenberg_extension() { |
||
| 816 | |||
| 817 | /** |
||
| 818 | * Can the current user access Publicize Data. |
||
| 819 | * |
||
| 820 | * @param int $post_id. 0 for general access. Post_ID for specific access. |
||
| 821 | * @return bool |
||
| 822 | */ |
||
| 823 | function current_user_can_access_publicize_data( $post_id = 0 ) { |
||
| 841 | |||
| 842 | /** |
||
| 843 | * Auth callback for the protected ->POST_MESS post_meta |
||
| 844 | * |
||
| 845 | * @param bool $allowed |
||
| 846 | * @param string $meta_key |
||
| 847 | * @param int $object_id Post ID |
||
| 848 | * @return bool |
||
| 849 | */ |
||
| 850 | function message_meta_auth_callback( $allowed, $meta_key, $object_id ) { |
||
| 853 | |||
| 854 | /** |
||
| 855 | * Registers the ->POST_MESS post_meta for use in the REST API. |
||
| 856 | * |
||
| 857 | * Registers for each post type that with `publicize` feature support. |
||
| 858 | */ |
||
| 859 | function register_post_meta() { |
||
| 881 | |||
| 882 | /** |
||
| 883 | * Fires when a post is saved, checks conditions and saves state in postmeta so that it |
||
| 884 | * can be picked up later by @see ::publicize_post() on WordPress.com codebase. |
||
| 885 | * |
||
| 886 | * Attached to the `save_post` action. |
||
| 887 | * |
||
| 888 | * @param int $post_id |
||
| 889 | * @param WP_Post $post |
||
| 890 | * @return void |
||
| 891 | */ |
||
| 892 | function save_meta( $post_id, $post ) { |
||
| 1047 | |||
| 1048 | /** |
||
| 1049 | * Alters the "Post Published" message to include information about where the post |
||
| 1050 | * was Publicized to. |
||
| 1051 | * |
||
| 1052 | * Attached to the `post_updated_messages` filter |
||
| 1053 | * |
||
| 1054 | * @param string[] $messages |
||
| 1055 | * @return string[] |
||
| 1056 | */ |
||
| 1057 | public function update_published_message( $messages ) { |
||
| 1123 | |||
| 1124 | /** |
||
| 1125 | * Get the Connections the Post was just Publicized to. |
||
| 1126 | * |
||
| 1127 | * Only reliable just after the Post was published. |
||
| 1128 | * |
||
| 1129 | * @param int $post_id |
||
| 1130 | * @return string[] Array of Service display name => Connection display name |
||
| 1131 | */ |
||
| 1132 | function get_publicizing_services( $post_id ) { |
||
| 1154 | |||
| 1155 | /** |
||
| 1156 | * Is the post Publicize-able? |
||
| 1157 | * |
||
| 1158 | * Only valid prior to Publicizing a Post. |
||
| 1159 | * |
||
| 1160 | * @param WP_Post $post |
||
| 1161 | * @return bool |
||
| 1162 | */ |
||
| 1163 | function post_is_publicizeable( $post ) { |
||
| 1178 | |||
| 1179 | /** |
||
| 1180 | * Is a given post type Publicize-able? |
||
| 1181 | * |
||
| 1182 | * Not every CPT lends itself to Publicize-ation. Allow CPTs to register by adding their CPT via |
||
| 1183 | * the publicize_post_types array filter. |
||
| 1184 | * |
||
| 1185 | * @param string $post_type The post type to check. |
||
| 1186 | * @return bool True if the post type can be Publicized. |
||
| 1187 | */ |
||
| 1188 | function post_type_is_publicizeable( $post_type ) { |
||
| 1194 | |||
| 1195 | /** |
||
| 1196 | * Already-published posts should not be Publicized by default. This filter sets checked to |
||
| 1197 | * false if a post has already been published. |
||
| 1198 | * |
||
| 1199 | * Attached to the `publicize_checkbox_default` filter |
||
| 1200 | * |
||
| 1201 | * @param bool $checked |
||
| 1202 | * @param int $post_id |
||
| 1203 | * @param string $service_name 'facebook', 'twitter', etc |
||
| 1204 | * @param object|array The Connection object (WordPress.com) or array (Jetpack) |
||
| 1205 | * @return bool |
||
| 1206 | */ |
||
| 1207 | function publicize_checkbox_default( $checked, $post_id, $service_name, $connection ) { |
||
| 1214 | |||
| 1215 | /* |
||
| 1216 | * Util |
||
| 1217 | */ |
||
| 1218 | |||
| 1219 | /** |
||
| 1220 | * Converts a Publicize message template string into a sprintf format string |
||
| 1221 | * |
||
| 1222 | * @param string[] $args |
||
| 1223 | * 0 - The Publicize message template: 'Check out my post: %title% @ %url' |
||
| 1224 | * ... - The template tags 'title', 'url', etc. |
||
| 1225 | * @return string |
||
| 1226 | */ |
||
| 1227 | protected static function build_sprintf( $args ) { |
||
| 1240 | } |
||
| 1241 | |||
| 1255 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: