PluginProbe
Force Refresh / 2.1.4
Force Refresh v2.1.4
3.2.1 3.2.0 3.1.2 3.1.1 3.1.0 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.11.0 2.11.1 2.12.0 All 54 releases
force-refresh / includes / actions / admin / inc.refresh-post.php

inc.refresh-post.php in Force Refresh 2.1.4, at includes/actions/admin/inc.refresh-post.php

80 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Action responsible for adding the area to request a refresh of a specific page.
4 *
5 * @package ForceRefresh
6 */
7
8 namespace JordanLeven\Plugins\ForceRefresh;
9
10 /**
11 * Main function to generate the admin HTML.
12 *
13 * @return void
14 */
15 function force_refresh_specific_page_refresh_html() {
16 define( 'HTML_CLASS_META_BOX', 'force-refresh-meta-box' );
17 define( 'FILE_NAME_META_BOX_ADMIN', 'force-refresh-meta-box-admin-js' );
18 // Include the admin JS.
19 add_script( FILE_NAME_META_BOX_ADMIN, '/dist/js/force-refresh-meta-box-admin.js', true );
20 // Get the current screen.
21 $current_screen = get_current_screen();
22 // Create the data we're going to localize to the script.
23 $localized_data = array(
24 // Wrap in inner array to preserve primitive types.
25 'localData' => array(
26 // Add the API URL for the script.
27 'apiUrl' => get_stylesheet_directory_uri(),
28 // Add the API URL for the script.
29 'siteId' => get_current_blog_id(),
30 // Create a nonce for the user.
31 'nonce' => wp_create_nonce( WP_FORCE_REFRESH_ACTION ),
32 // Create a nonce for the user.
33 'postId' => get_the_ID(),
34 'postType' => $current_screen->post_type,
35 'postName' => get_the_title(),
36 'targetClass' => HTML_CLASS_META_BOX,
37 // Add the refresh interval.
38 'refreshInterval' => get_option(
39 WP_FORCE_REFRESH_OPTION_REFRESH_INTERVAL_IN_SECONDS,
40 WP_FORCE_REFRESH_OPTION_REFRESH_INTERVAL_IN_SECONDS_DEFAULT
41 ),
42 ),
43 );
44 // Localize the data.
45 wp_localize_script( FILE_NAME_META_BOX_ADMIN, 'forceRefreshLocalJs', $localized_data );
46 // Now that it's registered, enqueue the script.
47 wp_enqueue_script( FILE_NAME_META_BOX_ADMIN );
48 echo '<div class="' . esc_html( HTML_CLASS_META_BOX ) . '"></div>';
49 }
50
51 // Add meta boxes for specific pages that we want to refresh.
52 add_action(
53 'add_meta_boxes',
54 function() {
55 // All post types.
56 $all_post_types = get_post_types();
57 // Loop through all the post types.
58 foreach ( $all_post_types as $post_type => $post_key ) {
59 // Get the post type attributes.
60 $post_type_attributes = get_post_type_object( $post_type );
61 // The post types public attribute.
62 $post_type_is_public = $post_type_attributes->public;
63 // Only add the box if the post type is public and we're not excluding
64 // the post type.
65 if ( $post_type_is_public
66 && ! in_array( $post_type, WP_FORCE_REFRESH_EXCLUDE_FROM_POST_TYPES, true )
67 ) {
68 // Add the box.
69 add_meta_box(
70 'force_refresh_specific_page_refresh',
71 'Force Refresh',
72 __NAMESPACE__ . '\\force_refresh_specific_page_refresh_html',
73 $post_type,
74 'side'
75 );
76 }
77 }
78 }
79 );
80