related-posts.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Module Name: Related posts
  4. * Module Description: Increase page views by showing related content to your visitors.
  5. * Jumpstart Description: Keep visitors engaged on your blog by highlighting relevant and new content at the bottom of each published post.
  6. * First Introduced: 2.9
  7. * Sort Order: 29
  8. * Recommendation Order: 9
  9. * Requires Connection: Yes
  10. * Auto Activate: No
  11. * Module Tags: Recommended
  12. * Feature: Engagement, Jumpstart
  13. * Additional Search Queries: related, related posts
  14. */
  15. class Jetpack_RelatedPosts_Module {
  16. /**
  17. * Class variables
  18. */
  19. private static $__instance = null;
  20. /**
  21. * Singleton implementation
  22. *
  23. * @return object
  24. */
  25. public static function instance() {
  26. if ( ! is_a( self::$__instance, 'Jetpack_RelatedPosts_Module' ) )
  27. self::$__instance = new Jetpack_RelatedPosts_Module();
  28. return self::$__instance;
  29. }
  30. /**
  31. * Register actions and filters
  32. *
  33. * @uses add_action, add_filter
  34. */
  35. private function __construct() {
  36. add_action( 'jetpack_module_loaded_related-posts', array( $this, 'action_on_load' ) );
  37. }
  38. /**
  39. * This action triggers if the module is in an active state, load related posts and options.
  40. *
  41. * @uses Jetpack_RelatedPosts::init, is_admin, Jetpack::enable_module_configurable, Jetpack::module_configuration_load, Jetpack_Sync::sync_posts
  42. * @return null
  43. */
  44. public function action_on_load() {
  45. require_once 'related-posts/jetpack-related-posts.php';
  46. Jetpack_RelatedPosts::init();
  47. if ( is_admin() ) {
  48. // Enable "Configure" button on module card
  49. Jetpack::enable_module_configurable( __FILE__ );
  50. Jetpack::module_configuration_load( __FILE__, array( $this, 'module_configuration_load' ) );
  51. }
  52. // Load Customizer controls.
  53. if ( class_exists( 'WP_Customize_Manager' ) ) {
  54. require_once 'related-posts/class.related-posts-customize.php';
  55. }
  56. }
  57. /**
  58. * Redirect configure button to Settings > Reading
  59. *
  60. * @uses wp_safe_redirect, admin_url
  61. * @return null
  62. */
  63. public function module_configuration_load() {
  64. wp_safe_redirect( admin_url( 'options-reading.php#jetpack_relatedposts' ) );
  65. exit;
  66. }
  67. }
  68. // Do it.
  69. Jetpack_RelatedPosts_Module::instance();