base, array( 'upload', 'post', 'media' ), true ) || in_array( $screen->id, self::SCREENS, true ); /** * Filter whether the PictureEditor launcher loads on an admin screen. * * @param bool $wants Decision. * @param \WP_Screen $screen Screen. */ return (bool) apply_filters( 'pictureeditor_load_on_screen', $wants, $screen ); } /** * Settings page script: copy diagnostics and erase local drafts. * * @param string $hook Current admin page hook. */ public static function enqueue_settings( $hook ) { if ( 'settings_page_pictureeditor' !== $hook ) { return; } wp_enqueue_script( 'pictureeditor-settings', PICTUREEDITOR_URL . 'assets/settings.js', array(), PICTUREEDITOR_VERSION, true ); wp_localize_script( 'pictureeditor-settings', 'pictureeditorSettings', array( 'copied' => __( 'Copied.', 'pictureeditor' ), 'draftsErased' => __( 'Drafts erased in this browser.', 'pictureeditor' ), 'draftsFailed' => __( 'Could not erase drafts.', 'pictureeditor' ), ) ); } /** * Enqueue the tiny launcher and its configuration. */ public static function enqueue() { if ( ! self::screen_wants_launcher() ) { return; } $v = PICTUREEDITOR_VERSION; wp_enqueue_script( 'pictureeditor-launcher', PICTUREEDITOR_URL . 'assets/launcher.js', array(), $v, true ); $screen = get_current_screen(); $context = 0; if ( $screen && 'post' === $screen->base && isset( $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $context = absint( $_GET['post'] ); // phpcs:ignore WordPress.Security.NonceVerification } $settings = Settings::all(); $config = array( 'restRoot' => esc_url_raw( rest_url( Rest::NS . '/' ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'editorJs' => PICTUREEDITOR_URL . 'assets/editor.js?ver=' . rawurlencode( $v ), 'editorCss' => PICTUREEDITOR_URL . 'assets/editor.css?ver=' . rawurlencode( $v ), 'version' => $v, 'userId' => get_current_user_id(), 'siteId' => get_current_blog_id(), 'locale' => determine_locale(), 'contextPost' => $context, 'contextType' => $context ? get_post_type( $context ) : '', 'mediaEditUrl' => admin_url( 'post.php?action=edit&post=' ), 'maxUploadBytes' => wp_max_upload_size(), 'defaults' => array( 'outputMime' => $settings['default_format'], 'quality' => $settings['quality'] / 100, 'allowedOutputMimes' => $settings['allowed_formats'], 'draftsEnabled' => (bool) $settings['drafts_enabled'], 'keepAltText' => (bool) $settings['keep_alt'], 'filenameSuffix' => $settings['filename_suffix'], ), 'editableMimes' => Capabilities::EDITABLE_MIMES, 'strings' => pictureeditor_strings(), 'labels' => array( 'edit' => __( 'Edit with PictureEditor', 'pictureeditor' ), 'editShort' => _x( 'Edit', 'product gallery image action', 'pictureeditor' ), 'loadError' => __( 'PictureEditor could not load. Check your connection and try again.', 'pictureeditor' ), ), ); /** * Filter the configuration passed to the browser editor. * * @param array $config Config. */ $config = apply_filters( 'pictureeditor_editor_config', $config ); wp_add_inline_script( 'pictureeditor-launcher', 'window.PictureEditorWPConfig = ' . wp_json_encode( $config ) . ';', 'before' ); wp_add_inline_style( 'common', '.pictureeditor-open .dashicons{vertical-align:text-bottom}.attachment-details .pictureeditor-open{margin-left:8px}' ); } /** * List-mode row action. * * @param array $actions Actions. * @param \WP_Post $post Attachment. * @return array */ public static function row_action( $actions, $post ) { if ( Capabilities::can_edit( $post->ID ) ) { $actions['pictureeditor'] = sprintf( '%s', (int) $post->ID, /* translators: %s: attachment title */ esc_attr( sprintf( __( 'Edit “%s” with PictureEditor', 'pictureeditor' ), get_the_title( $post ) ) ), esc_html__( 'Edit with PictureEditor', 'pictureeditor' ) ); } return $actions; } /** * Button on the single attachment edit screen. * * @param \WP_Post $post Attachment. */ public static function attachment_button( $post ) { if ( ! Capabilities::can_edit( $post->ID ) ) { return; } printf( '
', (int) $post->ID, esc_html__( 'Edit with PictureEditor', 'pictureeditor' ) ); $backups = Saver::backups( $post->ID ); if ( $backups && Capabilities::can_replace( $post->ID ) ) { printf( '
%s
', (int) $post->ID, esc_html__( 'Restore previous version', 'pictureeditor' ), /* translators: %s: date */ esc_html( sprintf( __( 'replaced %s', 'pictureeditor' ), wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), (int) $backups[0]['time'] ) ) ), (int) $post->ID, esc_html__( 'Delete backups permanently', 'pictureeditor' ) ); } } /** * "Edit with PictureEditor" under the featured image box. * * @param string $html Box HTML. * @param int $post_id Post. * @param int|null $thumbnail_id Attachment. * @return string */ public static function thumbnail_link( $html, $post_id, $thumbnail_id ) { if ( $thumbnail_id && Capabilities::can_edit( (int) $thumbnail_id ) ) { $html .= sprintf( '

%s

', (int) $thumbnail_id, esc_html__( 'Edit with PictureEditor', 'pictureeditor' ) ); } return $html; } /** * Settings link on the Plugins screen. * * @param array $links Links. * @return array */ public static function action_links( $links ) { array_unshift( $links, sprintf( '%s', esc_url( admin_url( 'options-general.php?page=pictureeditor' ) ), esc_html__( 'Settings', 'pictureeditor' ) ) ); return $links; } /** * Settings page. */ public static function menu() { add_options_page( __( 'PictureEditor', 'pictureeditor' ), __( 'PictureEditor', 'pictureeditor' ), 'manage_options', 'pictureeditor', array( __CLASS__, 'render_settings' ) ); } /** * Register the option with its sanitizer. */ public static function register_settings() { register_setting( 'pictureeditor', Settings::OPTION, array( 'type' => 'array', 'sanitize_callback' => array( 'PictureEditor\\Settings', 'sanitize' ), 'default' => Settings::defaults(), 'show_in_rest' => false, ) ); if ( isset( $_POST['pictureeditor_clear_log'] ) && check_admin_referer( 'pictureeditor_clear_log' ) && current_user_can( 'manage_options' ) ) { Log::clear(); add_settings_error( 'pictureeditor', 'log', __( 'Save log cleared.', 'pictureeditor' ), 'updated' ); } } /** * Roles that can upload files. * * @return array slug => name */ private static function upload_roles() { $out = array(); foreach ( wp_roles()->roles as $slug => $role ) { if ( ! empty( $role['capabilities']['upload_files'] ) ) { $out[ $slug ] = translate_user_role( $role['name'] ); } } return $out; } /** * Render the settings screen. */ public static function render_settings() { if ( ! current_user_can( 'manage_options' ) ) { return; } $s = Settings::all(); $roles = self::upload_roles(); $name = Settings::OPTION; $fmts = array( 'image/jpeg' => 'JPEG', 'image/png' => 'PNG', 'image/webp' => 'WebP', ); $offload = Compat::offload_plugins(); ?>

PICTUREEDITOR_VERSION, 'wordpress' => $wp_version, 'php' => PHP_VERSION, 'multisite' => is_multisite(), 'woocommerce' => defined( 'WC_VERSION' ) ? WC_VERSION : null, 'image_editor' => _wp_image_editor_choose(), 'max_upload' => wp_max_upload_size(), 'offload_plugins' => $offload, 'uploads_writable' => wp_is_writable( wp_get_upload_dir()['basedir'] ), 'settings' => array_diff_key( $s, array( 'roles' => 1, 'replace_roles' => 1 ) ), ); ?>

#' . (int) $e['source'] . '' : '—'; ?> #' . (int) $e['result'] . '' : '—'; ?> #' . (int) $e['product'] . '' : '—'; ?>