*/ class Amp_WP_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; if( get_transient( 'amp-wp-flush-rules' ) ) { add_action( 'admin_init', 'flush_rewrite_rules' ); delete_transient( 'amp-wp-flush-rules' ); } add_action( 'admin_menu', array( $this, 'amp_wp_admin_links' ), 999 ); add_action('admin_bar_menu', array( $this, 'amp_wp_add_toolbar_item' ), 100); /** * Classes responsible for defining all actions that occur in the admin area. */ require_once AMPWP_TEMPLATE_DIR_PATH . 'includes/admin/class-amp-wp-settings.php'; require_once AMPWP_TEMPLATE_DIR_PATH . 'includes/customizer/class-amp-wp-customize.php'; require_once AMPWP_TEMPLATE_DIR_PATH . 'includes/admin/class-amp-wp-add-ons.php'; /** * The class responsible for orchestrating the actions and filters of the * core plugin. */ require_once AMPWP_TEMPLATE_DIR_PATH . 'admin/class-amp-wp-meta-box.php'; // Filter -> Footer Branding - with Pixelative Logo add_filter('admin_footer_text', array( $this, 'amp_wp_powered_by' )); } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/amp-wp-admin.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts() { wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/amp-wp-admin.js', array( 'jquery' ), $this->version, false ); } public function amp_wp_admin_links() { add_menu_page( 'AMP WP', // string $page_title 'AMP WP', // string $menu_title 'manage_options', // string $capability 'amp-wp-welcome', // string $menu_slug array( $this, 'amp_wp_welcome' ), // callable $function plugins_url( 'amp-wp/admin/images/amp-wp-icon.svg' ), // string $icon_url 25 // int $position ); add_submenu_page( 'amp-wp-welcome', // string $parent_slug 'Welcome', // string $page_title 'Welcome', // string $menu_title 'manage_options', // string $capability 'amp-wp-welcome' // string $menu_slug ); } public function amp_wp_welcome() { $tab = filter_input(INPUT_GET, 'tab'); if( 'credits' === $tab ) : require_once AMPWP_TEMPLATE_DIR_PATH . 'admin/partials/amp-wp-admin-credits.php'; else: require_once AMPWP_TEMPLATE_DIR_PATH . 'admin/partials/amp-wp-admin-welcome.php'; endif; } /** * Check If the admin page is from AMP WP. * * @since 1.0.0 */ public function is_amp_wp_admin_pages() { $screen = get_current_screen(); return ( 'amp-wp-welcome' === $screen->parent_base ) ? true : false; } /** * Add AMP Link to Admin Bar * * @param object $admin_bar * @since 1.0.0 * @access public * @return void */ public function amp_wp_add_toolbar_item( $wp_admin_bar ) { $wp_admin_bar->add_menu( array( 'parent' => 'site-name', 'id' => 'view-amp', 'title' => __('Visit AMP', 'amp-wp'), 'href' => amp_wp_site_url(), 'meta' => false, )); } /** * Replace admin footer text with Brand. * * @since 1.0.0 */ public function amp_wp_powered_by($text) { if( is_admin() && $this->is_amp_wp_admin_pages() ) { $text = 'Powered by Pixlative'; } return $text; } } /** * AMP WP Version Check * * @since 1.2.0 */ function amp_wp_version_check_using_wpapi() { $url = 'https://api.wordpress.org/plugins/info/1.0/amp-wp.json'; $response = wp_remote_get($url); // Check for error if( is_wp_error( $response ) ) { return; } // Parse remote HTML file $data = json_decode( wp_remote_retrieve_body( $response ) ); // Check for error if( is_wp_error( $data ) ) { return; } if( !empty( $data ) ) { return $data->version; } }