Нема описа

publicize.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
  2. /**
  3. * Module Name: Publicize
  4. * Module Description: Publicize makes it easy to share your site’s posts on several social media networks automatically when you publish a new post.
  5. * Sort Order: 10
  6. * Recommendation Order: 7
  7. * First Introduced: 2.0
  8. * Requires Connection: Yes
  9. * Requires User Connection: Yes
  10. * Auto Activate: No
  11. * Module Tags: Social, Recommended
  12. * Feature: Engagement
  13. * Additional Search Queries: facebook, jetpack publicize, twitter, tumblr, linkedin, social, tweet, connections, sharing, social media, automated, automated sharing, auto publish, auto tweet and like, auto tweet, facebook auto post, facebook posting
  14. *
  15. * @package automattic/jetpack
  16. */
  17. /**
  18. * Class Jetpack_Publicize
  19. */
  20. class Jetpack_Publicize {
  21. /**
  22. * If Publicize is executing within Jetpack.
  23. *
  24. * @var bool
  25. */
  26. public $in_jetpack = true;
  27. /**
  28. * Jetpack_Publicize constructor.
  29. */
  30. public function __construct() {
  31. global $publicize_ui;
  32. $this->in_jetpack = ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'enable_module_configurable' ) ) ? true : false;
  33. if ( $this->in_jetpack ) {
  34. Jetpack::enable_module_configurable( __FILE__ );
  35. }
  36. require_once __DIR__ . '/publicize/publicize.php';
  37. if ( $this->in_jetpack ) {
  38. require_once __DIR__ . '/publicize/publicize-jetpack.php';
  39. } else {
  40. require_once dirname( __DIR__ ) . '/mu-plugins/keyring/keyring.php';
  41. require_once __DIR__ . '/publicize/publicize-wpcom.php';
  42. }
  43. require_once __DIR__ . '/publicize/ui.php';
  44. $publicize_ui = new Publicize_UI();
  45. $publicize_ui->in_jetpack = $this->in_jetpack;
  46. // Jetpack specific checks / hooks.
  47. if ( $this->in_jetpack ) {
  48. // if sharedaddy isn't active, the sharing menu hasn't been added yet.
  49. $active = Jetpack::get_active_modules();
  50. if ( in_array( 'publicize', $active, true ) && ! in_array( 'sharedaddy', $active, true ) ) {
  51. add_action( 'admin_menu', array( &$publicize_ui, 'sharing_menu' ) );
  52. }
  53. /*
  54. * The Publicize Options array does not currently have UI since it is being added
  55. * for a specific purpose and not part of a broader Publicize sprint.
  56. *
  57. * In order to pass the settings up to WordPress.com, we are updating an option to Sync will pass it up.
  58. * To make it relatively easy for use, we are creating a filter that checks if the option and filter match.
  59. *
  60. * This only runs when a post is saved to avoid it running too much.
  61. */
  62. add_action(
  63. 'save_post',
  64. function () {
  65. $publicize_options = get_option( 'jetpack_publicize_options', array() );
  66. /**
  67. * Filters the options for Publicize.
  68. *
  69. * As of Jetpack 8.5, the array keys could be:
  70. * attach_media bool If Publicize should send the image to the social media platform. Default false.
  71. *
  72. * @module publicize
  73. *
  74. * @since 8.5.0
  75. *
  76. * @param array $options Array of Publicize options.
  77. */
  78. $filtered = (array) apply_filters( 'jetpack_publicize_options', $publicize_options );
  79. if ( $publicize_options !== $filtered ) {
  80. update_option( 'jetpack_publicize_options', $filtered, false );
  81. }
  82. }
  83. );
  84. }
  85. }
  86. }
  87. new Jetpack_Publicize();
  88. if ( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) && ! function_exists( 'publicize_init' ) ) {
  89. /**
  90. * Helper for grabbing a Publicize object from the "front-end" (non-admin) of
  91. * a site. Normally Publicize is only loaded in wp-admin, so there's a little
  92. * set up that you might need to do if you want to use it on the front end.
  93. * Just call this function and it returns a Publicize object.
  94. *
  95. * @return Publicize Object
  96. */
  97. function publicize_init() {
  98. global $publicize;
  99. if ( ! class_exists( 'Publicize' ) ) {
  100. require_once __DIR__ . '/publicize/publicize.php';
  101. }
  102. return $publicize;
  103. }
  104. }