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( '
| #' . (int) $e['source'] . '' : '—'; ?> | #' . (int) $e['result'] . '' : '—'; ?> | #' . (int) $e['product'] . '' : '—'; ?> |