1<?php
2/**
3 * Press This Display and Handler.
4 *
5 * @package WordPress
6 * @subpackage Press_This
7 */
8
9define( 'IFRAME_REQUEST', true );
10
11/** WordPress Administration Bootstrap */
12require_once __DIR__ . '/admin.php';
13
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 __( '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(
31 add_query_arg(
32 array(
33 'action' => 'activate',
34 'plugin' => $plugin_file,
35 'from' => 'press-this',
36 ),
37 admin_url( 'plugins.php' )
38 ),
39 'activate-plugin_' . $plugin_file
40 );
41 $action = sprintf(
42 '<a href="%1$s" aria-label="%2$s">%2$s</a>',
43 esc_url( $url ),
44 __( 'Activate Press This' )
45 );
46 } else {
47 if ( is_main_site() ) {
48 $url = wp_nonce_url(
49 add_query_arg(
50 array(
51 'action' => 'install-plugin',
52 'plugin' => $plugin_slug,
53 'from' => 'press-this',
54 ),
55 self_admin_url( 'update.php' )
56 ),
57 'install-plugin_' . $plugin_slug
58 );
59 $action = sprintf(
60 '<a href="%1$s" class="install-now" data-slug="%2$s" data-name="%2$s" aria-label="%3$s">%3$s</a>',
61 esc_url( $url ),
62 esc_attr( $plugin_slug ),
63 _x( 'Install Now', 'plugin' )
64 );
65 } else {
66 $action = sprintf(
67 /* translators: %s: URL to Press This bookmarklet on the main site. */
68 __( 'Press This is not installed. Please install Press This from <a href="%s">the main site</a>.' ),
69 get_admin_url( get_current_network_id(), 'press-this.php' )
70 );
71 }
72 }
73 wp_die(
74 __( 'The Press This plugin is required.' ) . '<br />' . $action,
75 __( 'Installation Required' ),
76 200
77 );
78 } else {
79 wp_die(
80 __( 'Press This is not available. Please contact your site administrator.' ),
81 __( 'Installation Required' ),
82 200
83 );
84 }
85}
86
87wp_load_press_this();
88