wp/wp-admin/press-this.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Press_This
     6  * @subpackage Press_This
     7  */
     7  */
     8 
     8 
     9 define('IFRAME_REQUEST' , true);
     9 define( 'IFRAME_REQUEST' , true );
    10 
    10 
    11 /** WordPress Administration Bootstrap */
    11 /** WordPress Administration Bootstrap */
    12 require_once( dirname( __FILE__ ) . '/admin.php' );
    12 require_once( dirname( __FILE__ ) . '/admin.php' );
    13 
    13 
    14 if ( ! current_user_can( 'edit_posts' ) || ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) )
    14 function wp_load_press_this() {
    15 	wp_die( __( 'Cheatin’ uh?' ), 403 );
    15 	$plugin_slug = 'press-this';
       
    16 	$plugin_file = 'press-this/press-this-plugin.php';
    16 
    17 
    17 if ( empty( $GLOBALS['wp_press_this'] ) ) {
    18 	if ( ! current_user_can( 'edit_posts' ) || ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
    18 	include( ABSPATH . 'wp-admin/includes/class-wp-press-this.php' );
    19 		wp_die(
       
    20 			__( 'Sorry, you are not allowed to create posts as this user.' ),
       
    21 			__( 'You need a higher level of permission.' ),
       
    22 			403
       
    23 		);
       
    24 	} elseif ( is_plugin_active( $plugin_file ) ) {
       
    25 		include( WP_PLUGIN_DIR . '/press-this/class-wp-press-this-plugin.php' );
       
    26 		$wp_press_this = new WP_Press_This_Plugin();
       
    27 		$wp_press_this->html();
       
    28 	} elseif ( current_user_can( 'activate_plugins' ) ) {
       
    29 		if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_file ) ) {
       
    30 			$url = wp_nonce_url( add_query_arg( array(
       
    31 				'action' => 'activate',
       
    32 				'plugin' => $plugin_file,
       
    33 				'from'   => 'press-this',
       
    34 			), admin_url( 'plugins.php' ) ), 'activate-plugin_' . $plugin_file );
       
    35 			$action = sprintf(
       
    36 				'<a href="%1$s" aria-label="%2$s">%2$s</a>',
       
    37 				esc_url( $url ),
       
    38 				__( 'Activate Press This' )
       
    39 			);
       
    40 		} else {
       
    41 			if ( is_main_site() ) {
       
    42 				$url = wp_nonce_url( add_query_arg( array(
       
    43 					'action' => 'install-plugin',
       
    44 					'plugin' => $plugin_slug,
       
    45 					'from'   => 'press-this',
       
    46 				), self_admin_url( 'update.php' ) ), 'install-plugin_' . $plugin_slug );
       
    47 				$action = sprintf(
       
    48 					'<a href="%1$s" class="install-now" data-slug="%2$s" data-name="%2$s" aria-label="%3$s">%3$s</a>',
       
    49 					esc_url( $url ),
       
    50 					esc_attr( $plugin_slug ),
       
    51 					__( 'Install Now' )
       
    52 				);
       
    53 			} else {
       
    54 				$action = sprintf(
       
    55 					/* translators: URL to wp-admin/press-this.php */
       
    56 					__( 'Press This is not installed. Please install Press This from <a href="%s">the main site</a>.' ),
       
    57 					get_admin_url( get_current_network_id(), 'press-this.php' )
       
    58 				);
       
    59 			}
       
    60 		}
       
    61 		wp_die(
       
    62 			__( 'The Press This plugin is required.' ) . '<br />' . $action,
       
    63 			__( 'Installation Required' ),
       
    64 			200
       
    65 		);
       
    66 	} else {
       
    67 		wp_die(
       
    68 			__( 'Press This is not available. Please contact your site administrator.' ),
       
    69 			__( 'Installation Required' ),
       
    70 			200
       
    71 		);
       
    72 	}
    19 }
    73 }
    20 
    74 
    21 $GLOBALS['wp_press_this']->html();
    75 wp_load_press_this();