enhanced-distribution.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Module Name: Enhanced Distribution
  4. * Module Description: Increase reach and traffic.
  5. * Sort Order: 5
  6. * First Introduced: 1.2
  7. * Requires Connection: Yes
  8. * Auto Activate: Public
  9. * Module Tags: Writing
  10. * Feature: Engagement
  11. * Additional Search Queries: google, seo, firehose, search, broadcast, broadcasting
  12. */
  13. // In case it's active prior to upgrading to 1.9
  14. function jetpack_enhanced_distribution_before_activate_default_modules() {
  15. $old_version = Jetpack_Options::get_option( 'old_version' );
  16. list( $old_version ) = explode( ':', $old_version );
  17. if ( version_compare( $old_version, '1.9-something', '>=' ) ) {
  18. return;
  19. }
  20. Jetpack::check_privacy( __FILE__ );
  21. }
  22. add_action( 'jetpack_before_activate_default_modules', 'jetpack_enhanced_distribution_before_activate_default_modules' );
  23. /**
  24. * If a request has ?get_freshly_pressed_data=true appended
  25. * to the end, then let's provide the necessary data back via JSON.
  26. */
  27. if ( isset( $_GET['get_freshly_pressed_data'] ) ) {
  28. add_action( 'template_redirect', 'jetpack_get_freshly_pressed_data' );
  29. function jetpack_get_freshly_pressed_data() {
  30. if ( is_single() ) {
  31. wp_send_json_success( array(
  32. 'blog_id' => Jetpack_Options::get_option( 'id' ),
  33. 'post_id' => get_the_ID(),
  34. ) );
  35. } else {
  36. wp_send_json_error( array(
  37. 'message' => 'Not Singular',
  38. ) );
  39. }
  40. }
  41. }
  42. add_action( 'rss_head', 'jetpack_enhanced_distribution_feed_id' );
  43. add_action( 'rss_item', 'jetpack_enhanced_distribution_post_id' );
  44. add_action( 'rss2_head', 'jetpack_enhanced_distribution_feed_id' );
  45. add_action( 'rss2_item', 'jetpack_enhanced_distribution_post_id' );
  46. function jetpack_enhanced_distribution_feed_id(){
  47. (int) $id = Jetpack_Options::get_option( 'id' );
  48. if ( $id > 0 ) {
  49. $output = sprintf( '<site xmlns="com-wordpress:feed-additions:1">%d</site>', $id );
  50. echo $output;
  51. }
  52. }
  53. function jetpack_enhanced_distribution_post_id(){
  54. $id = get_the_ID();
  55. if ( $id ) {
  56. $output = sprintf( '<post-id xmlns="com-wordpress:feed-additions:1">%d</post-id>', $id );
  57. echo $output;
  58. }
  59. }