settings = $settings; $this->gate = $gate; $this->builder = new Graph_Builder( $settings, new Resolver( $settings, new Variable_Parser() ), new Breadcrumb_Trail( $settings ) ); } /** * Module id. * * @since 1.0.0 * * @return string */ public function id(): string { return 'schema'; } /** * Module name. * * @since 1.0.0 * * @return string */ public function label(): string { return __( 'Schema markup', 'elevenrank' ); } /** * Registers the module's hooks. * * @since 1.0.0 * * @return void */ public function boot(): void { add_action( 'rest_api_init', array( $this, 'register_routes' ) ); add_filter( 'elevenrank_editor_config', array( $this, 'editor_config' ) ); if ( $this->gate->is_active() ) { ( new Schema_Output( $this->builder ) )->hooks(); } } /** * Registers the REST route used by the editor. * * @since 1.0.0 * * @return void */ public function register_routes(): void { ( new Schema_Controller( $this->builder ) )->register_routes(); } /** * Gives the editor the types, their fields and the default of each post type. * * @since 1.0.0 * * @param mixed $config Editor configuration. * @return mixed */ public function editor_config( $config ) { if ( ! is_array( $config ) || ! current_user_can( Capabilities::EDIT_POST_ADVANCED ) ) { return $config; } $defaults = array(); foreach ( isset( $config['postTypes'] ) && is_array( $config['postTypes'] ) ? $config['postTypes'] : array() as $post_type ) { $defaults[ (string) $post_type ] = Schema_Fields::default_type( (string) $post_type, $this->settings ); } $config['schema'] = array( 'types' => Type_Definitions::describe(), 'defaults' => $defaults, ); return $config; } }