*/ 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); /** * 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( 'AMPWP', // string $page_title 'AMPWP', // 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 ); add_submenu_page( 'amp-wp-welcome', // string $parent_slug 'Translation', // string $page_title 'Translation', // string $menu_title 'manage_options', // string $capability 'amp-wp-translation', // string $menu_slug array( $this, 'amp_wp_translation' ) // callable $function ); add_submenu_page( 'amp-wp-welcome', // string $parent_slug 'Add-ons', // string $page_title 'Add-ons', // string $menu_title 'manage_options', // string $capability 'amp-wp-add-ons', // string $menu_slug array( $this, 'amp_wp_add_ons' ) // callable $function ); $customize_url = add_query_arg( array( 'return' => urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'url' => urlencode( amp_wp_site_url() ), 'autofocus' => array( 'panel' => 'amp-wp-panel' ) ), 'customize.php' ); add_submenu_page( 'amp-wp-welcome', _x( 'Customize AMP Theme', 'amp-wp' ), _x( 'Customize AMP', 'amp-wp' ), 'manage_options', $customize_url ); } 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; } public function amp_wp_translation() { require_once AMPWP_TEMPLATE_DIR_PATH . 'admin/partials/amp-wp-admin-translation.php'; } public function amp_wp_add_ons() { require_once AMPWP_TEMPLATE_DIR_PATH . 'admin/partials/amp-wp-admin-add-ons.php'; } /** * Check If the admin page is from AMPWP. * * @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; } }