PluginProbe ʕ •ᴥ•ʔ
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets / 4.0.7
Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets v4.0.7
4.2.5 4.2.4 trunk 3.7.10 3.7.11 3.7.12 3.7.13 3.7.14 3.7.2 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8 3.8.1 3.8.10 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.8.8 3.8.9 3.8.9.1 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.5.1 4.0.6 4.0.6.1 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.2.0 4.2.1 4.2.2 4.2.3
widget-options / includes / widgets / gutenberg / lib / experimental / rest-api.php
widget-options / includes / widgets / gutenberg / lib / experimental Last commit date
fonts-api 1 year ago interactivity-api 1 year ago block-editor-settings-mobile.php 1 year ago block-editor-settings.php 1 year ago blocks.php 1 year ago class-gutenberg-rest-global-styles-revisions-controller.php 1 year ago class-wp-classic-to-block-menu-converter.php 1 year ago class-wp-navigation-fallback-gutenberg.php 1 year ago class-wp-rest-block-editor-settings-controller.php 1 year ago class-wp-rest-customizer-nonces.php 1 year ago class-wp-rest-navigation-fallback-controller.php 1 year ago editor-settings.php 1 year ago kses.php 1 year ago l10n.php 1 year ago navigation-fallback.php 1 year ago navigation-theme-opt-in.php 1 year ago rest-api.php 1 year ago
rest-api.php
114 lines
1 <?php
2 /**
3 * PHP and WordPress configuration compatibility functions for the Gutenberg
4 * editor plugin changes related to REST API.
5 *
6 * @package gutenberg
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 die( 'Silence is golden.' );
11 }
12
13 /**
14 * Registers the customizer nonces REST API routes.
15 */
16 function gutenberg_register_rest_customizer_nonces() {
17 $customizer_nonces = new WP_Rest_Customizer_Nonces();
18 $customizer_nonces->register_routes();
19 }
20 add_action( 'rest_api_init', 'gutenberg_register_rest_customizer_nonces' );
21
22 /**
23 * Registers the Block editor settings REST API routes.
24 */
25 function gutenberg_register_block_editor_settings() {
26 $editor_settings = new WP_REST_Block_Editor_Settings_Controller();
27 $editor_settings->register_routes();
28 }
29 add_action( 'rest_api_init', 'gutenberg_register_block_editor_settings' );
30
31
32 /**
33 * Registers the Navigation Fallbacks REST API routes.
34 */
35 function gutenberg_register_rest_navigation_fallbacks() {
36 $editor_settings = new WP_REST_Navigation_Fallback_Controller();
37 $editor_settings->register_routes();
38 }
39 add_action( 'rest_api_init', 'gutenberg_register_rest_navigation_fallbacks' );
40
41
42 /**
43 * Shim for get_sample_permalink() to add support for auto-draft status.
44 *
45 * This function filters the return from get_sample_permalink() and essentially
46 * re-runs the same logic minus the filters, but pretends a status of auto-save
47 * is actually publish in order to return the future permalink format.
48 *
49 * This is a temporary fix until we can patch get_sample_permalink()
50 *
51 * @see https://core.trac.wordpress.org/ticket/46266
52 *
53 * @param array $permalink Array containing the sample permalink with placeholder for the post name, and the post name.
54 * @param int $id ID of the post.
55 * @param string $title Title of the post.
56 * @param string $name Slug of the post.
57 * @param object $post WP_Post object.
58 *
59 * @return array Array containing the sample permalink with placeholder for the post name, and the post name.
60 */
61 function gutenberg_auto_draft_get_sample_permalink( $permalink, $id, $title, $name, $post ) {
62 if ( 'auto-draft' !== $post->post_status ) {
63 return $permalink;
64 }
65 $ptype = get_post_type_object( $post->post_type );
66
67 $original_status = $post->post_status;
68 $original_date = $post->post_date;
69 $original_name = $post->post_name;
70
71 // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
72 $post->post_status = 'publish';
73 $post->post_name = sanitize_title( $post->post_name ? $post->post_name : $post->post_title, $post->ID );
74
75 // If the user wants to set a new name -- override the current one.
76 // Note: if empty name is supplied -- use the title instead, see #6072.
77 if ( ! is_null( $name ) ) {
78 $post->post_name = sanitize_title( $name ? $name : $title, $post->ID );
79 }
80
81 $post->post_name = wp_unique_post_slug( $post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent );
82
83 $post->filter = 'sample';
84
85 $permalink = get_permalink( $post, true );
86
87 // Replace custom post_type Token with generic pagename token for ease of use.
88 $permalink = str_replace( "%$post->post_type%", '%pagename%', $permalink );
89
90 // Handle page hierarchy.
91 if ( $ptype->hierarchical ) {
92 $uri = get_page_uri( $post );
93 if ( $uri ) {
94 $uri = untrailingslashit( $uri );
95 $uri = strrev( stristr( strrev( $uri ), '/' ) );
96 $uri = untrailingslashit( $uri );
97 }
98
99 if ( ! empty( $uri ) ) {
100 $uri .= '/';
101 }
102 $permalink = str_replace( '%pagename%', "{$uri}%pagename%", $permalink );
103 }
104
105 $permalink = array( $permalink, $post->post_name );
106 $post->post_status = $original_status;
107 $post->post_date = $original_date;
108 $post->post_name = $original_name;
109 unset( $post->filter );
110
111 return $permalink;
112 }
113 add_filter( 'get_sample_permalink', 'gutenberg_auto_draft_get_sample_permalink', 10, 5 );
114