plugin = $plugin; } /** * Registers hooks. */ public function register() { add_action( 'add_meta_boxes', array( $this, 'add' ) ); add_action( 'save_post', array( $this, 'save' ), 10, 2 ); add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_sidebar' ) ); } /** * Whether a post type gets the block-editor sidebar instead of the box. * * The sidebar saves through the REST API, which only exposes meta for * post types that support custom fields; others keep the box. * * @param string $post_type Post type. * @return bool */ public function uses_sidebar( $post_type ) { return post_type_supports( $post_type, 'custom-fields' ) && use_block_editor_for_post_type( $post_type ); } /** * Adds the box to every managed post type. Where the block editor sidebar * is used, the box appears in the classic editor only. */ public function add() { foreach ( array_keys( $this->plugin->types->post_types() ) as $post_type ) { add_meta_box( 'orbitstem-seo', __( 'Orbitstem SEO', 'orbitstem-seo' ), array( $this, 'render' ), $post_type, 'normal', 'default', array( '__back_compat_meta_box' => $this->uses_sidebar( $post_type ) ) ); } } /** * Loads the block-editor sidebar for managed post types. */ public function enqueue_sidebar() { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen || ! $screen->post_type || ! $this->plugin->types->supports_post_type( $screen->post_type ) || ! $this->uses_sidebar( $screen->post_type ) ) { return; } $types = array(); foreach ( array_keys( $this->plugin->types->post_types() ) as $post_type ) { $types[ $post_type ] = array( 'title' => (string) $this->plugin->settings->post_type( $post_type, 'title' ), 'description' => (string) $this->plugin->settings->post_type( $post_type, 'description' ), 'schema' => (string) $this->plugin->settings->post_type( $post_type, 'schema' ), 'typeName' => wp_specialchars_decode( (string) get_post_type_object( $post_type )->labels->name, ENT_QUOTES ), ); } wp_enqueue_script( 'orbitstem-seo-editor', ORBITSTEM_SEO_URL . 'assets/editor.js', array( 'wp-plugins', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-components', 'wp-data', 'wp-i18n', 'wp-api-fetch', 'wp-block-editor', 'wp-core-data' ), ORBITSTEM_SEO_VERSION, true ); wp_enqueue_style( 'orbitstem-seo-editor', ORBITSTEM_SEO_URL . 'assets/editor.css', array(), ORBITSTEM_SEO_VERSION ); wp_add_inline_script( 'orbitstem-seo-editor', 'window.orbitstemSeoEditor = ' . wp_json_encode( array( 'types' => $types, 'schemaTypes' => Settings::schema_types(), 'autoRedirect' => (bool) $this->plugin->settings->get( 'guardian_auto_redirect' ), 'siteName' => wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), 'tagline' => wp_specialchars_decode( get_bloginfo( 'description' ), ENT_QUOTES ), 'separator' => $this->plugin->settings->separator(), 'homeUrl' => home_url( '/' ), 'locale' => get_locale(), 'defaultImage' => (string) $this->plugin->settings->get( 'og_default_image' ), 'twitterSite' => (string) $this->plugin->settings->get( 'twitter_site' ), 'richTypes' => \Orbitstem\SEO\Schema\RichTypes::definitions(), 'currencies' => \Orbitstem\SEO\Schema\RichTypes::currencies(), 'wooProduct' => \Orbitstem\SEO\Schema\Woo::active() && 'product' === $screen->post_type, 'canIndexing' => ( function () use ( $screen ) { $type = get_post_type_object( $screen->post_type ); return $type && current_user_can( $type->cap->publish_posts ); } )(), ) ) . ';', 'before' ); wp_set_script_translations( 'orbitstem-seo-editor', 'orbitstem-seo' ); } /** * Renders the box. * * @param WP_Post $post Post being edited. */ public function render( $post ) { $meta = $this->plugin->meta; $resolved = $this->plugin->resolver->for_post( $post ); $type = $post->post_type; wp_nonce_field( self::NONCE_ACTION, self::NONCE_FIELD ); ?>
Settings. Variables such as %1$s and %2$s work here too.', 'orbitstem-seo' ),
'%title%',
'%sitename%'
);
?>
" placeholder="plugin->settings->post_type( $type, 'title' ) ); ?>" />
" placeholder="" />