*/ 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' )); add_action('admin_notices', array( $this, 'amp_wp_update_notice' )); } /** * 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 ); 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 ); $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 ); 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 ); } 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() { $amp_wp_translation_option = get_option('amp-wp-translation'); $sections['comments'] = array( 'title' => __('Comments Area', 'amp-wp' ), 'id' => 'comments-area', 'type' => 'section', 'fields' => apply_filters('amp_wp_comment_fields', array( array( 'id' => 'comments', 'type' => 'text', 'title' => __('Comments', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['comments'] ) ) ? esc_attr( $amp_wp_translation_option['comments'] ) : __('Comments', 'amp-wp' ), 'placeholder' => __('Comments', 'amp-wp' ), ), array( 'id' => 'add_comment', 'type' => 'text', 'title' => __('Add Comment', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['add_comment'] ) ) ? esc_attr( $amp_wp_translation_option['add_comment'] ) : __('Add Comment', 'amp-wp' ), 'placeholder' => __('Add Comment', 'amp-wp' ) ), array( 'id' => 'comments_edit', 'type' => 'text', 'title' => __('Edit Comment', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['comments_edit'] ) ) ? esc_attr( $amp_wp_translation_option['comments_edit'] ) : __('Edit Comment', 'amp-wp' ), 'placeholder' => __('Edit Comment', 'amp-wp' ) ), array( 'id' => 'comments_reply', 'type' => 'text', 'title' => __('Leave a Reply', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['comments_reply'] ) ) ? esc_attr( $amp_wp_translation_option['comments_reply'] ) : __('Leave a Reply', 'amp-wp' ), 'placeholder' => __('Leave a Reply', 'amp-wp' ), ), array( 'id' => 'comments_reply_to', 'type' => 'text', 'title' => __('Reply To %s', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['comments_reply_to'] ) ) ? esc_attr( $amp_wp_translation_option['comments_reply_to'] ) : __('Reply To %s', 'amp-wp' ), 'placeholder' => __('Reply To %s', 'amp-wp' ) ), array( 'id' => 'comment_successful_message', 'type' => 'text', 'title' => __('Thank You Message', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['comment_successful_message'] ) ) ? esc_attr( $amp_wp_translation_option['comment_successful_message'] ) : __('Thank you for submitting comment, we will review it and will get back to you.', 'amp-wp' ), 'placeholder' => __('Thank you for submitting comment, we will review it and will get back to you.', 'amp-wp' ) ), array( 'id' => 'cancel_reply_text', 'type' => 'text', 'title' => __('Cancel reply', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['cancel_reply_text'] ) ) ? esc_attr( $amp_wp_translation_option['cancel_reply_text'] ) : __('Cancel reply', 'amp-wp' ), 'placeholder' => __('Cancel reply', 'amp-wp' ) ), array( 'id' => 'post_comment_text', 'type' => 'text', 'title' => __('Post Comment', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['post_comment_text'] ) ) ? esc_attr( $amp_wp_translation_option['post_comment_text'] ) : __('Post Comment', 'amp-wp' ), 'placeholder' => __('Post Comment', 'amp-wp' ) ), array( 'id' => 'loggedin_text', 'type' => 'text', 'title' => __('Logged in as', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['loggedin_text'] ) ) ? esc_attr( $amp_wp_translation_option['loggedin_text'] ) : __('Logged in as', 'amp-wp' ), 'placeholder' => __('Logged in as', 'amp-wp' ) ), array( 'id' => 'logout_text', 'type' => 'text', 'title' => __('Log Out', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['logout_text'] ) ) ? esc_attr( $amp_wp_translation_option['logout_text'] ) : __('Log Out', 'amp-wp' ), 'placeholder' => __('Log Out', 'amp-wp' ) ), array( 'id' => 'name_text', 'type' => 'text', 'title' => __('Name', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['name_text'] ) ) ? esc_attr( $amp_wp_translation_option['name_text'] ) : __('Name', 'amp-wp' ), 'placeholder' => __('Name', 'amp-wp' ) ), array( 'id' => 'email_text', 'type' => 'text', 'title' => __('Email', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['email_text'] ) ) ? esc_attr( $amp_wp_translation_option['email_text'] ) : __('Email', 'amp-wp' ), 'placeholder' => __('Email', 'amp-wp' ) ), array( 'id' => 'website_text', 'type' => 'text', 'title' => __('Website', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['website_text'] ) ) ? esc_attr( $amp_wp_translation_option['website_text'] ) : __('Website', 'amp-wp' ), 'placeholder' => __('Website', 'amp-wp' ) ), array( 'id' => 'your_email_address_text', 'type' => 'text', 'title' => __('Your email address will not be published.', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['your_email_address_text'] ) ) ? esc_attr( $amp_wp_translation_option['your_email_address_text'] ) : __('Your email address will not be published.', 'amp-wp' ), 'placeholder' => __('Your email address will not be published.', 'amp-wp' ) ), array( 'id' => 'required_fields_text', 'type' => 'text', 'title' => __('Required fields are marked', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['required_fields_text'] ) ) ? esc_attr( $amp_wp_translation_option['required_fields_text'] ) : __('Required fields are marked', 'amp-wp' ), 'placeholder' => __('Required fields are marked', 'amp-wp' ) ), array( 'id' => 'comment_text', 'type' => 'text', 'title' => __('Comment', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['comment_text'] ) ) ? esc_attr( $amp_wp_translation_option['comment_text'] ) : __('Comment', 'amp-wp' ), 'placeholder' => __('Comment', 'amp-wp' ) ), array( 'id' => 'comment_previous', 'type' => 'text', 'title' => __('Previous', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['comment_previous'] ) ) ? esc_attr( $amp_wp_translation_option['comment_previous'] ) : __('Previous', 'amp-wp' ), 'placeholder' => __('Previous', 'amp-wp' ) ), array( 'id' => 'comment_next', 'type' => 'text', 'title' => __('Next', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['comment_next'] ) ) ? esc_attr( $amp_wp_translation_option['comment_next'] ) : __('Next', 'amp-wp' ), 'placeholder' => __('Next', 'amp-wp' ) ), array( 'id' => 'comment_page_numbers', 'type' => 'text', 'title' => __('Page %1$s of %2$s', 'amp-wp' ), 'default' => ( isset( $amp_wp_translation_option ) && !empty( $amp_wp_translation_option['comment_page_numbers'] ) ) ? esc_attr( $amp_wp_translation_option['comment_page_numbers'] ) : __('Page %1$s of %2$s', 'amp-wp' ), 'placeholder' => __('Page %1$s of %2$s', 'amp-wp' ) ), )), ); if(isset( $_POST ) ) { $amp_wp_translation = filter_input_array( INPUT_POST ); if( $amp_wp_translation ) : foreach ( $amp_wp_translation as $key => $value ) { if( strstr( $key, 'amp-wp-translation' ) ) { update_option( sanitize_key( $key ), $value ); } } endif; } 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 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; } function amp_wp_update_notice() { $screen = ''; $screen = get_current_screen(); if( 'toplevel_page_amp-wp-welcome' == $screen->base || 'amp-wp_page_amp-wp-add-ons' == $screen->base ) { ?>