PluginProbe
Gutenify – Visual Site Builder Blocks & Starter Templates / 1.8.0
Gutenify – Visual Site Builder Blocks & Starter Templates v1.8.0
1.9.0 1.8.0 1.7.0 1.6.6 1.6.5 1.6.4 trunk 0.0.1 0.0.2 0.0.3 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 All 74 releases
gutenify / core / inc / helpers / helpers.php

helpers.php in Gutenify – Visual Site Builder Blocks & Starter Templates 1.8.0, at core/inc/helpers/helpers.php

116 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Prevent direct access to the file.
5 *
6 * Ensures this file is being loaded within the WordPress environment.
7 */
8 defined( 'ABSPATH' ) || exit;
9
10 /**
11 * Helpers file.
12 *
13 * @package Gutenify
14 */
15 /**
16 * Settings.
17 *
18 * @return array
19 */
20 function gutenify_settings() {
21 $default_settings = array(
22 'active_post_types' => array( 'post', 'page' ),
23 'skip_gutenburg_post_type' => apply_filters( 'gutenify_skip_gutenburg_post_type', array() ),
24 );
25 $current_settings = get_option( 'gutenify_settings', array() );
26 $settings = wp_parse_args( $current_settings, $default_settings );
27 return $settings;
28 }
29
30 /**
31 * Update settings.
32 *
33 * @param array $new_settings New settings.
34 * @return array
35 */
36 function gutenify_update_settings( $new_settings ) {
37 $settings = gutenify_settings();
38 $settings = wp_parse_args( $new_settings, $settings );
39 update_option( 'gutenify_settings', $settings );
40 return $settings;
41 }
42
43 function gutenify_get_block_asset_file_values( $path ) {
44 $asset_path = $path;
45
46 return file_exists( $asset_path )
47 ? include $asset_path
48 : array(
49 'dependencies' => array(),
50 'version' => GUTENIFY_VERSION,
51 );
52 }
53
54 function gutenify_update_global_styles( $new_settings, $new_styles ) {
55 // Get the user's global styles CPT id.
56 $user_custom_post_type_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
57 $global_styles_controller = new WP_REST_Global_Styles_Controller();
58
59 $update_request = new WP_REST_Request( 'PUT', '/wp/v2/global-styles/' );
60 $update_request->set_param( 'id', $user_custom_post_type_id );
61 $update_request->set_param( 'settings', $new_settings );
62 $update_request->set_param( 'styles', $new_styles );
63
64 $res = $global_styles_controller->update_item( $update_request );
65
66 // Ideally the call to update_item would delete all of the appropriate transients and caches
67 delete_transient( 'global_styles' );
68 delete_transient( 'global_styles_' . get_stylesheet() );
69 delete_transient( 'gutenberg_global_styles' );
70 delete_transient( 'gutenberg_global_styles_' . get_stylesheet() );
71
72 if ( class_exists( 'WP_Theme_JSON_Resolver_Gutenberg' ) ) {
73 WP_Theme_JSON_Resolver_Gutenberg::clean_cached_data();
74 }
75 }
76
77 /**
78 * Returns the posts for an internal posts.
79 *
80 * @param array $posts Current posts.
81 *
82 * @return array Returns posts.
83 */
84 function gutenify_get_post_info( $posts ) {
85
86 $formatted_posts = array();
87
88 foreach ( $posts as $post ) {
89
90 $formatted_post = null;
91
92 $formatted_post['thumbnailURL'] = get_the_post_thumbnail_url( $post );
93 $formatted_post['date'] = esc_attr( get_the_date( 'c', $post ) );
94 $formatted_post['dateReadable'] = esc_html( get_the_date( '', $post ) );
95 $formatted_post['title'] = get_the_title( $post );
96 $formatted_post['postLink'] = esc_url( get_permalink( $post ) );
97 $formatted_post['ID'] = absint( $post->ID );
98 $formatted_post['author_id'] = absint( $post->post_author );
99
100 $post_excerpt = $post->post_excerpt;
101
102 if ( ! ( $post_excerpt ) ) {
103
104 $post_excerpt = $post->post_content;
105
106 }
107
108 $formatted_post['postExcerpt'] = $post_excerpt;
109
110 $formatted_posts[] = $formatted_post;
111
112 }
113
114 return $formatted_posts;
115 }
116