init_hooks(); } /** * Initialize hooks. * * @access private * @since 1.0.0 */ private function init_hooks() { add_action( 'plugin_loaded', array( $this, 'check_alnp_installed' ) ); add_action( 'init', array( $this, 'load_text_domain' ), 0 ); add_action( 'wp_enqueue_scripts', array( $this, 'alnp_enqueue_scripts' ) ); } // END init_hooks() /** * Checks if Auto Load Next Post is installed. * * @access public * @since 1.0.0 * @return bool */ public function check_alnp_installed() { if ( ! defined( 'AUTO_LOAD_NEXT_POST_VERSION' ) || version_compare( AUTO_LOAD_NEXT_POST_VERSION, $this->required_alnp, '<' ) ) { add_action( 'admin_notices', array( $this, 'alnp_not_installed' ) ); return false; } } // END check_alnp_installed() /** * Auto Load Next Post is Not Installed Notice. * * @access public * @since 1.0.0 * @return void */ public function alnp_not_installed() { echo '

' . sprintf( __( 'Auto Load Next Post: Facebook Pixel Tracking requires $1%s v$2%s or higher to be installed.', 'alnp-facebook-pixel-tracking' ), 'Auto Load Next Post', $this->required_alnp ) . '

'; } // END alnp_not_installed() /** * Get the Plugin URL. * * @access public * @static * @since 1.0.0 * @return string */ public static function plugin_url() { return plugins_url( basename( plugin_dir_path(__FILE__) ), basename( __FILE__ ) ); } // END plugin_url() /** * Load the plugin text domain once the plugin has initialized. * * @access public * @since 1.0.0 * @return void */ public function load_text_domain() { load_plugin_textdomain( 'alnp-facebook-pixel-tracking', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } // END load_text_domain() /** * Load JS only on the front end for a single post. * * @access public * @since 1.0.0 * @return void */ public function alnp_enqueue_scripts() { if ( is_singular() && in_array( get_post_type(), $this->allowed_post_types() ) ) { wp_register_script( 'alnp-facebook-pixel-tracking', $this->plugin_url() . '/assets/js/alnp-facebook-pixel-tracking.js', array( 'jquery' ), self::$version ); wp_enqueue_script( 'alnp-facebook-pixel-tracking' ); wp_localize_script( 'alnp-facebook-pixel-tracking', 'alnp_fb_pixel', array( 'alnpVersion' => AUTO_LOAD_NEXT_POST_VERSION, 'pluginVersion' => self::$version, )); } } // END alnp_enqueue_scripts() /** * Returns allowed post types to track page views. * * @access public * @since 1.0.0 * @return array */ public function allowed_post_types() { return array( 'post' ); } // END allowed_post_types() } // END class } // END if class exists return ALNP_FB_Pixel_Tracking::instance();