Advertisement
Guest User

jnews-auto-load-post.php

a guest
Dec 7th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.33 KB | None | 0 0
  1. <?php
  2. /*
  3.     Plugin Name: JNews - Auto Load Next Post
  4.     Plugin URI: http://jegtheme.com/
  5.     Description: Auto load next post when scroll for JNews
  6.     Version: 1.0.3
  7.     Author: Jegtheme
  8.     Author URI: http://jegtheme.com
  9.     License: GPL2
  10. */
  11.  
  12. defined( 'JNEWS_AUTOLOAD_POST' )                or define( 'JNEWS_AUTOLOAD_POST', 'jnews-auto-load-post');
  13. defined( 'JNEWS_AUTOLOAD_POST_URL' )            or define( 'JNEWS_AUTOLOAD_POST_URL', plugins_url(JNEWS_AUTOLOAD_POST));
  14. defined( 'JNEWS_AUTOLOAD_POST_FILE' )           or define( 'JNEWS_AUTOLOAD_POST_FILE',  __FILE__ );
  15. defined( 'JNEWS_AUTOLOAD_POST_DIR' )            or define( 'JNEWS_AUTOLOAD_POST_DIR', plugin_dir_path( __FILE__ ) );
  16.  
  17. /**
  18.  * Get jnews option
  19.  *
  20.  * @param $setting
  21.  * @param $default
  22.  * @return mixed
  23.  */
  24. if(!function_exists('jnews_get_option'))
  25. {
  26.     function jnews_get_option($setting, $default = null)
  27.     {
  28.         $options = get_option( 'jnews_option', array() );
  29.         $value = $default;
  30.         if ( isset( $options[ $setting ] ) ) {
  31.             $value = $options[ $setting ];
  32.         }
  33.         return $value;
  34.     }
  35. }
  36.  
  37. /**
  38.  * Load script for JNews Autoload
  39.  */
  40. add_action('wp_enqueue_scripts', 'jnews_auto_load_assets');
  41.  
  42. if( !function_exists('jnews_auto_load_assets') )
  43. {
  44.     function jnews_auto_load_assets()
  45.     {
  46.         if(!is_customize_preview())
  47.         {
  48.             wp_enqueue_script('jnews-autoload', JNEWS_AUTOLOAD_POST_URL . '/assets/js/jquery.autoload.js', array('jquery'), null, true);
  49.         }
  50.     }
  51. }
  52.  
  53. /**
  54.  * Single post load class
  55.  */
  56. add_filter( 'jnews_post_wrap_class' , 'jnews_autoload_post_wrap_class');
  57.  
  58. if(!function_exists('jnews_autoload_post_wrap_class'))
  59. {
  60.     function jnews_autoload_post_wrap_class($class)
  61.     {
  62.         $class .= ' post-autoload ';
  63.         return $class;
  64.     }
  65. }
  66.  
  67. /**
  68.  * Single post autoload attribute
  69.  */
  70. add_filter('jnews_post_wrap_attribute', 'jnews_autoload_post_wrap_attribute', null, 2);
  71.  
  72. if(!function_exists('jnews_autoload_post_wrap_attribute'))
  73. {
  74.     function jnews_autoload_post_wrap_attribute($attribute, $post_id)
  75.     {
  76.         $attribute .= " data-url=\"" . get_permalink($post_id) . "\" data-title=\"" . esc_attr(get_the_title($post_id)) . "\" data-id=\"" . esc_attr(get_the_ID()) . "\" ";
  77.  
  78.         $prev_post = get_previous_post();
  79.  
  80.         if(!empty($prev_post)) {
  81.             $attribute .= " data-prev=\"" . esc_url(get_permalink($prev_post->ID)) . "\" ";
  82.         }
  83.  
  84.         return $attribute;
  85.     }
  86. }
  87.  
  88. /**
  89.  * Single post prev next
  90.  */
  91. add_filter('jnews_single_show_prev_next_post', 'jnews_autoload_single_show_prev_next_post');
  92.  
  93. if(!function_exists('jnews_autoload_single_show_prev_next_post'))
  94. {
  95.     function jnews_autoload_single_show_prev_next_post()
  96.     {
  97.         return false;
  98.     }
  99. }
  100.  
  101. /**
  102.  * Single popup post
  103.  */
  104. add_filter('jnews_single_show_popup_post', 'jnews_autoload_single_show_popup_post');
  105.  
  106. if(!function_exists('jnews_autoload_single_show_popup_post'))
  107. {
  108.     function jnews_autoload_single_show_popup_post()
  109.     {
  110.         return false;
  111.     }
  112. }
  113.  
  114. /**
  115.  * Add Rewrite Endpoint
  116.  */
  117. add_action( 'init', 'jnews_load_next_post_rewrite_endpoint');
  118.  
  119. if(!function_exists('jnews_load_next_post_rewrite_endpoint'))
  120. {
  121.     function jnews_load_next_post_rewrite_endpoint()
  122.     {
  123.         add_rewrite_endpoint('autoload', EP_PERMALINK);
  124.     }
  125. }
  126.  
  127. /**
  128.  * Activation hook
  129.  */
  130. if(!function_exists('jnews_autoload_activation_hook'))
  131. {
  132.     register_activation_hook( __FILE__, 'jnews_autoload_activation_hook' );
  133.  
  134.     function jnews_autoload_activation_hook()
  135.     {
  136.         jnews_load_next_post_rewrite_endpoint();
  137.  
  138.         global $wp_rewrite;
  139.         $wp_rewrite->flush_rules();
  140.     }
  141. }
  142.  
  143. /**
  144.  * Template Redirect
  145.  */
  146. add_action('template_redirect', 'jnews_auto_load_next_post_template_redirect');
  147.  
  148. if(!function_exists('jnews_auto_load_next_post_template_redirect'))
  149. {
  150.     function jnews_auto_load_next_post_template_redirect()
  151.     {
  152.         global $wp_query;
  153.  
  154.         if ( ! isset($wp_query->query_vars['autoload']) || ! is_singular()) {
  155.             return;
  156.         }
  157.  
  158.         require 'autoload-template.php';
  159.         exit;
  160.     }
  161. }
  162.  
  163. /**
  164.  * Register customizer option
  165.  */
  166. add_action( 'jnews_register_customizer_option', 'jnews_autoload_customizer_option');
  167.  
  168. if(!function_exists('jnews_autoload_customizer_option'))
  169. {
  170.     function jnews_autoload_customizer_option()
  171.     {
  172.         require_once 'class.jnews-auto-load-post-option.php';
  173.         JNews_Auto_Load_Post_Option::getInstance();
  174.     }
  175. }
  176.  
  177. add_filter( 'jnews_single_post_template', 'jnews_auto_load_single_post_template' );
  178.  
  179. if(!function_exists('jnews_auto_load_single_post_template'))
  180. {
  181.     function jnews_auto_load_single_post_template()
  182.     {
  183.         return jnews_get_option('autoload_blog_template', '1');
  184.     }
  185. }
  186.  
  187. add_filter( 'jnews_single_post_layout', 'jnews_auto_load_single_post_layout' );
  188.  
  189. if(!function_exists('jnews_auto_load_single_post_layout'))
  190. {
  191.     function jnews_auto_load_single_post_layout()
  192.     {
  193.         if(wp_is_mobile()) {
  194.             return 'no-sidebar';
  195.         } else {
  196.             return jnews_get_option('autoload_blog_layout', 'right-sidebar');
  197.         }
  198.  
  199.     }
  200. }
  201.  
  202. add_filter( 'jnews_single_post_sidebar', 'jnews_auto_load_single_post_sidebar' );
  203.  
  204. if(!function_exists('jnews_auto_load_single_post_sidebar'))
  205. {
  206.     function jnews_auto_load_single_post_sidebar()
  207.     {
  208.         return jnews_get_option('autoload_sidebar', 'default-sidebar');
  209.     }
  210. }
  211.  
  212. /**
  213.  * JNews Single Post
  214.  */
  215. add_action('jnews_single_post_after_content', 'jnews_auto_load_single_post_after_content', 45);
  216.  
  217. if(!function_exists('jnews_auto_load_single_post_after_content'))
  218. {
  219.     function jnews_auto_load_single_post_after_content()
  220.     {
  221.         $post_attr = jnews_autoload_post_wrap_attribute('', get_the_ID());
  222.         echo "<div class='jnews-autoload-splitter' {$post_attr}></div>";
  223.     }
  224. }
  225.  
  226. /**
  227.  * JNews Remove Comment
  228.  */
  229. add_filter('jnews_single_show_comment', 'jnews_auto_load_remove_comment');
  230.  
  231. function jnews_auto_load_remove_comment()
  232. {
  233.     if(jnews_get_option('autoload_disable_comment', 'hide') === 'hide')
  234.     {
  235.         return false;
  236.     }
  237.  
  238.     return true;
  239. }
  240.  
  241.  
  242. /**
  243.  * Load Text Domain
  244.  */
  245.  
  246. function jnews_auto_load_post_textdomain()
  247. {
  248.     load_plugin_textdomain( JNEWS_AUTOLOAD_POST, false, basename(__DIR__) . '/languages/' );
  249. }
  250.  
  251. jnews_auto_load_post_textdomain();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement