press-this.php 2.3 KB

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