Make WordPress Core


Ignore:
Timestamp:
09/24/2017 02:21:42 PM (7 years ago)
Author:
azaozz
Message:

Retire Press This and extract it to a plugin. First run.

Props kraftbj, azaozz.
See #41689.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/press-this.php

    r38470 r41584  
    77 */
    88
    9 define('IFRAME_REQUEST' , true);
     9define( 'IFRAME_REQUEST' , true );
    1010
    1111/** WordPress Administration Bootstrap */
    1212require_once( dirname( __FILE__ ) . '/admin.php' );
    1313
    14 if ( ! current_user_can( 'edit_posts' ) || ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
    15     wp_die(
    16         '<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
    17         '<p>' . __( 'Sorry, you are not allowed to create posts as this user.' ) . '</p>',
    18         403
    19     );
     14function wp_load_press_this() {
     15    $plugin_slug = 'press-this';
     16    $plugin_file = 'press-this/press-this-plugin.php';
     17
     18    if ( ! current_user_can( 'edit_posts' ) || ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
     19        wp_die(
     20            __( 'Sorry, you are not allowed to create posts as this user.' ),
     21            __( 'Cheatin&#8217; uh?' ),
     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            __( 'Install Required' ),
     64            200
     65        );
     66    } else {
     67        wp_die(
     68            __( 'Press This is not available. Please contact your site administrator.' ),
     69            __( 'Install Required' ),
     70            200
     71        );
     72    }
    2073}
    2174
    22 include( ABSPATH . 'wp-admin/includes/class-wp-press-this.php' );
    23 $wp_press_this = new WP_Press_This();
    24 $wp_press_this->html();
     75wp_load_press_this();
Note: See TracChangeset for help on using the changeset viewer.