@@ -11,220 +11,220 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Shortcodes' ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Redux Framework shortcode extension class. Takes the common WordPress functions `wp_get_theme()` and `bloginfo()` and a few other functions and makes them accessible via shortcodes. Below you will find a table for the possible shortcodes and their values. |
|
| 16 | - * | shortcode | Function | Description | |
|
| 17 | - * |-----------|----------|-------------| |
|
| 18 | - * | blog-name | bloginfo("name") | Displays the "Site Title" set in Settings > General. This data is retrieved from the "blogname" record in the wp_options table. | |
|
| 19 | - * | blog-description | bloginfo("description") | Displays the "Tagline" set in Settings > General. This data is retrieved from the "blogdescription" record in the wp_options table.| |
|
| 20 | - * | blog-wpurl | bloginfo("wpurl") | Displays the "WordPress address (URL)" set in Settings > General. This data is retrieved from the "siteurl" record in the wp_options table. Consider using **blog-root_url** instead, especially for multi-site configurations using paths instead of subdomains (it will return the root site not the current sub-site). | |
|
| 21 | - * | blog-root_url | site_url() | Return the root site, not the current sub-site. | |
|
| 22 | - * | blog-url | home_url() | Displays the "Site address (URL)" set in Settings > General. This data is retrieved from the "home" record in the wp_options table. | |
|
| 23 | - * | blog-admin_email | bloginfo("admin_email") | Displays the "E-mail address" set in Settings > General. This data is retrieved from the "admin_email" record in the wp_options table.| |
|
| 24 | - * | blog-charset | bloginfo("charset") | Displays the "Encoding for pages and feeds" set in Settings > Reading. This data is retrieved from the "blog_charset" record in the wp_options table. Note: In Version 3.5.0 and later, character encoding is no longer configurable from the Administration Panel. Therefore, this parameter always echoes "UTF-8", which is the default encoding of WordPress.| |
|
| 25 | - * | blog-version | bloginfo("version") | Displays the WordPress Version you use. This data is retrieved from the $wp_version variable set in wp-includes/version.php.| |
|
| 26 | - * | blog-html_type | bloginfo("html_type") | Displays the Content-Type of WordPress HTML pages (default: "text/html"). This data is retrieved from the "html_type" record in the wp_options table. Themes and plugins can override the default value using the pre_option_html_type filter.| |
|
| 27 | - * | blog-text_direction | bloginfo("text_direction") | Displays the Text Direction of WordPress HTML pages. Consider using **blog-text_direction_boolean** instead if you want a true/false response. | |
|
| 28 | - * | blog-text_direction_boolean | is_rtl() | Displays true/false check if the Text Direction of WordPress HTML pages is left instead of right | |
|
| 29 | - * | blog-language | bloginfo("language") | Displays the language of WordPress.| |
|
| 30 | - * | blog-stylesheet_url | get_stylesheet_uri() | Displays the primary CSS (usually style.css) file URL of the active theme. | |
|
| 31 | - * | blog-stylesheet_directory | bloginfo("stylesheet_directory") | Displays the stylesheet directory URL of the active theme. (Was a local path in earlier WordPress versions.) Consider echoing get_stylesheet_directory_uri() instead.| |
|
| 32 | - * | blog-template_url | get_template_directory_uri() | Parent template uri. Consider using **blog-child_template_url** for the child template URI. | |
|
| 33 | - * | blog-child_template_url | get_stylesheet_directory_uri() | Child template URI. | |
|
| 34 | - * | blog-pingback_url | bloginfo("pingback_url") | Displays the Pingback XML-RPC file URL (xmlrpc.php).| |
|
| 35 | - * | blog-atom_url | bloginfo("atom_url") | Displays the Atom feed URL (/feed/atom).| |
|
| 36 | - * | blog-rdf_url | bloginfo("rdf_url") | Displays the RDF/RSS 1.0 feed URL (/feed/rfd).| |
|
| 37 | - * | blog-rss_url | bloginfo("rss_url") | Displays the RSS 0.92 feed URL (/feed/rss).| |
|
| 38 | - * | blog-rss2_url | bloginfo("rss2_url") | Displays the RSS 2.0 feed URL (/feed).| |
|
| 39 | - * | blog-comments_atom_url | bloginfo("comments_atom_url") | Displays the comments Atom feed URL (/comments/feed).| |
|
| 40 | - * | blog-comments_rss2_url | bloginfo("comments_rss2_url") | Displays the comments RSS 2.0 feed URL (/comments/feed).| |
|
| 41 | - * | login-url | wp_login_url() | Returns the WordPress login URL. | |
|
| 42 | - * | login-url | wp_logout_url() | Returns the WordPress logout URL. | |
|
| 43 | - * | current_year | date("Y") | Returns the current year. | |
|
| 44 | - * | theme-name | $theme_info->get("Name") | Theme name as given in theme's style.css | |
|
| 45 | - * | theme-uri | $theme_info->get("ThemeURI") | The path to the theme's directory | |
|
| 46 | - * | theme-description | $theme_info->get("Description") | The description of the theme | |
|
| 47 | - * | theme-author | $theme_info->get("Author") | The theme's author | |
|
| 48 | - * | theme-author_uri | $theme_info->get("AuthorURI") | The website of the theme author | |
|
| 49 | - * | theme-version | $theme_info->get("Version") | The version of the theme | |
|
| 50 | - * | theme-template | $theme_info->get("Template") | The folder name of the current theme | |
|
| 51 | - * | theme-status | $theme_info->get("Status") | If the theme is published | |
|
| 52 | - * | theme-tags | $theme_info->get("Tags") | Tags used to describe the theme | |
|
| 53 | - * | theme-text_domain | $theme_info->get("TextDomain") | The text domain used in the theme for translation purposes | |
|
| 54 | - * | theme-domain_path | $theme_info->get("DomainPath") | Path to the theme translation files | |
|
| 55 | - * |
|
| 56 | - * @version 1.0.0 |
|
| 57 | - */ |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Class Redux_Shortcodes |
|
| 61 | - */ |
|
| 62 | - class Redux_Shortcodes { |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Redux_Shortcodes constructor. |
|
| 66 | - */ |
|
| 67 | - public function __construct() { |
|
| 68 | - if ( ! shortcode_exists( 'bloginfo' ) ) { |
|
| 69 | - add_shortcode( 'bloginfo', array( $this, 'blog_info' ) ); |
|
| 70 | - } else { |
|
| 71 | - add_shortcode( 'redux_bloginfo', array( $this, 'blog_info' ) ); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - if ( ! shortcode_exists( 'themeinfo' ) ) { |
|
| 75 | - add_shortcode( 'themeinfo', array( $this, 'theme_info' ) ); |
|
| 76 | - } else { |
|
| 77 | - add_shortcode( 'redux_themeinfo', array( $this, 'theme_info' ) ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - if ( ! shortcode_exists( 'date' ) ) { |
|
| 81 | - add_shortcode( 'date', array( $this, 'date' ) ); |
|
| 82 | - } else { |
|
| 83 | - add_shortcode( 'redux_date', array( $this, 'date' ) ); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Get shortcode data. |
|
| 89 | - * |
|
| 90 | - * @param array|string $atts Attributes. |
|
| 91 | - * @param string|null $content Content. |
|
| 92 | - * |
|
| 93 | - * @return bool|string|null |
|
| 94 | - */ |
|
| 95 | - public function blog_info( $atts = array(), ?string $content = null ) { |
|
| 96 | - if ( ! is_array( $atts ) ) { |
|
| 97 | - $atts = array(); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $content = sanitize_text_field( $content ); |
|
| 101 | - $atts = array_map( 'sanitize_text_field', wp_unslash( $atts ) ); |
|
| 102 | - |
|
| 103 | - if ( ! empty( $content ) && ! isset( $atts['data'] ) ) { |
|
| 104 | - $atts['data'] = $content; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - switch ( $atts['data'] ) { |
|
| 108 | - case 'stylesheet_directory': |
|
| 109 | - case 'child_template_directory': |
|
| 110 | - return get_stylesheet_directory(); |
|
| 111 | - case 'parent_template_url': |
|
| 112 | - return get_template_directory_uri(); |
|
| 113 | - case 'child_template_url': |
|
| 114 | - case 'template_url': |
|
| 115 | - return get_stylesheet_directory_uri(); |
|
| 116 | - case 'template_directory': |
|
| 117 | - return get_template_directory(); |
|
| 118 | - case 'text_direction': |
|
| 119 | - case 'text_direction_bool': |
|
| 120 | - case 'text_direction_boolean': |
|
| 121 | - return is_rtl(); |
|
| 122 | - case 'is_multisite': |
|
| 123 | - return is_multisite(); |
|
| 124 | - case 'url': |
|
| 125 | - return esc_url( home_url() ); |
|
| 126 | - case 'root_url': |
|
| 127 | - return esc_url( site_url() ); |
|
| 128 | - case 'stylesheet_url': |
|
| 129 | - return esc_url( get_stylesheet_uri() ); |
|
| 130 | - case 'logout_url': |
|
| 131 | - return esc_url( wp_logout_url() ); |
|
| 132 | - case 'login_url': |
|
| 133 | - return esc_url( wp_login_url() ); |
|
| 134 | - case 'register_url': |
|
| 135 | - return esc_url( wp_registration_url() ); |
|
| 136 | - case 'lostpassword_url': |
|
| 137 | - case 'lost_password_url': |
|
| 138 | - return esc_url( wp_lostpassword_url() ); |
|
| 139 | - default: |
|
| 140 | - return get_bloginfo( $atts['data'] ); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Get theme info. |
|
| 146 | - * |
|
| 147 | - * @param array|string $atts Attributes. |
|
| 148 | - * @param string|null $content Content. |
|
| 149 | - * |
|
| 150 | - * @return array|bool|string |
|
| 151 | - */ |
|
| 152 | - public function theme_info( array $atts = array(), ?string $content = null ) { |
|
| 153 | - if ( ! is_array( $atts ) ) { |
|
| 154 | - $atts = array(); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - $content = sanitize_text_field( $content ); |
|
| 158 | - $atts = array_map( 'sanitize_text_field', wp_unslash( $atts ) ); |
|
| 159 | - |
|
| 160 | - if ( ! empty( $content ) && ! isset( $atts['data'] ) ) { |
|
| 161 | - $atts['data'] = $content; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - if ( empty( $this->theme_info ) ) { |
|
| 165 | - $this->theme_info = wp_get_theme(); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $keys = array( |
|
| 169 | - 'name' => 'Name', |
|
| 170 | - 'themeuri' => 'ThemeURI', |
|
| 171 | - 'theme_uri' => 'ThemeURI', |
|
| 172 | - 'description' => 'Description', |
|
| 173 | - 'author' => 'Author', |
|
| 174 | - 'authoruri' => 'AuthorURI', |
|
| 175 | - 'author_uri' => 'AuthorURI', |
|
| 176 | - 'version' => 'Version', |
|
| 177 | - 'template' => 'Template', |
|
| 178 | - 'status' => 'Status', |
|
| 179 | - 'tags' => 'Tags', |
|
| 180 | - 'textdomain' => 'TextDomain', |
|
| 181 | - 'text_domain' => 'TextDomain', |
|
| 182 | - 'domainpath' => 'DomainPath', |
|
| 183 | - 'domain_path' => 'DomainPath', |
|
| 184 | - 'is_child' => 'is_child', |
|
| 185 | - ); |
|
| 186 | - |
|
| 187 | - $atts['data'] = $keys[ strtolower( $atts['data'] ) ]; |
|
| 188 | - |
|
| 189 | - switch ( $atts['data'] ) { |
|
| 190 | - case 'is_child': |
|
| 191 | - return Redux_Helpers::is_child_theme( get_template_directory() ); |
|
| 192 | - default: |
|
| 193 | - $return = $this->theme_info->get( $atts['data'] ); |
|
| 194 | - |
|
| 195 | - if ( is_array( $return ) ) { |
|
| 196 | - $return = implode( ', ', $return ); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $return; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Get date info. |
|
| 205 | - * |
|
| 206 | - * @param array|string $atts Attributes. |
|
| 207 | - * @param string|null $content Content. |
|
| 208 | - * |
|
| 209 | - * @return false|string |
|
| 210 | - */ |
|
| 211 | - public function date( $atts = array(), ?string $content = null ) { |
|
| 212 | - if ( ! is_array( $atts ) ) { |
|
| 213 | - $atts = array(); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - $content = sanitize_text_field( $content ); |
|
| 217 | - $atts = array_map( 'sanitize_text_field', wp_unslash( $atts ) ); |
|
| 218 | - |
|
| 219 | - if ( ! empty( $content ) && ! isset( $atts['data'] ) ) { |
|
| 220 | - $atts['data'] = $content; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - if ( empty( $atts['data'] ) ) { |
|
| 224 | - $atts['data'] = 'Y'; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - return gmdate( $atts['data'] ); |
|
| 228 | - } |
|
| 229 | - } |
|
| 14 | + /** |
|
| 15 | + * Redux Framework shortcode extension class. Takes the common WordPress functions `wp_get_theme()` and `bloginfo()` and a few other functions and makes them accessible via shortcodes. Below you will find a table for the possible shortcodes and their values. |
|
| 16 | + * | shortcode | Function | Description | |
|
| 17 | + * |-----------|----------|-------------| |
|
| 18 | + * | blog-name | bloginfo("name") | Displays the "Site Title" set in Settings > General. This data is retrieved from the "blogname" record in the wp_options table. | |
|
| 19 | + * | blog-description | bloginfo("description") | Displays the "Tagline" set in Settings > General. This data is retrieved from the "blogdescription" record in the wp_options table.| |
|
| 20 | + * | blog-wpurl | bloginfo("wpurl") | Displays the "WordPress address (URL)" set in Settings > General. This data is retrieved from the "siteurl" record in the wp_options table. Consider using **blog-root_url** instead, especially for multi-site configurations using paths instead of subdomains (it will return the root site not the current sub-site). | |
|
| 21 | + * | blog-root_url | site_url() | Return the root site, not the current sub-site. | |
|
| 22 | + * | blog-url | home_url() | Displays the "Site address (URL)" set in Settings > General. This data is retrieved from the "home" record in the wp_options table. | |
|
| 23 | + * | blog-admin_email | bloginfo("admin_email") | Displays the "E-mail address" set in Settings > General. This data is retrieved from the "admin_email" record in the wp_options table.| |
|
| 24 | + * | blog-charset | bloginfo("charset") | Displays the "Encoding for pages and feeds" set in Settings > Reading. This data is retrieved from the "blog_charset" record in the wp_options table. Note: In Version 3.5.0 and later, character encoding is no longer configurable from the Administration Panel. Therefore, this parameter always echoes "UTF-8", which is the default encoding of WordPress.| |
|
| 25 | + * | blog-version | bloginfo("version") | Displays the WordPress Version you use. This data is retrieved from the $wp_version variable set in wp-includes/version.php.| |
|
| 26 | + * | blog-html_type | bloginfo("html_type") | Displays the Content-Type of WordPress HTML pages (default: "text/html"). This data is retrieved from the "html_type" record in the wp_options table. Themes and plugins can override the default value using the pre_option_html_type filter.| |
|
| 27 | + * | blog-text_direction | bloginfo("text_direction") | Displays the Text Direction of WordPress HTML pages. Consider using **blog-text_direction_boolean** instead if you want a true/false response. | |
|
| 28 | + * | blog-text_direction_boolean | is_rtl() | Displays true/false check if the Text Direction of WordPress HTML pages is left instead of right | |
|
| 29 | + * | blog-language | bloginfo("language") | Displays the language of WordPress.| |
|
| 30 | + * | blog-stylesheet_url | get_stylesheet_uri() | Displays the primary CSS (usually style.css) file URL of the active theme. | |
|
| 31 | + * | blog-stylesheet_directory | bloginfo("stylesheet_directory") | Displays the stylesheet directory URL of the active theme. (Was a local path in earlier WordPress versions.) Consider echoing get_stylesheet_directory_uri() instead.| |
|
| 32 | + * | blog-template_url | get_template_directory_uri() | Parent template uri. Consider using **blog-child_template_url** for the child template URI. | |
|
| 33 | + * | blog-child_template_url | get_stylesheet_directory_uri() | Child template URI. | |
|
| 34 | + * | blog-pingback_url | bloginfo("pingback_url") | Displays the Pingback XML-RPC file URL (xmlrpc.php).| |
|
| 35 | + * | blog-atom_url | bloginfo("atom_url") | Displays the Atom feed URL (/feed/atom).| |
|
| 36 | + * | blog-rdf_url | bloginfo("rdf_url") | Displays the RDF/RSS 1.0 feed URL (/feed/rfd).| |
|
| 37 | + * | blog-rss_url | bloginfo("rss_url") | Displays the RSS 0.92 feed URL (/feed/rss).| |
|
| 38 | + * | blog-rss2_url | bloginfo("rss2_url") | Displays the RSS 2.0 feed URL (/feed).| |
|
| 39 | + * | blog-comments_atom_url | bloginfo("comments_atom_url") | Displays the comments Atom feed URL (/comments/feed).| |
|
| 40 | + * | blog-comments_rss2_url | bloginfo("comments_rss2_url") | Displays the comments RSS 2.0 feed URL (/comments/feed).| |
|
| 41 | + * | login-url | wp_login_url() | Returns the WordPress login URL. | |
|
| 42 | + * | login-url | wp_logout_url() | Returns the WordPress logout URL. | |
|
| 43 | + * | current_year | date("Y") | Returns the current year. | |
|
| 44 | + * | theme-name | $theme_info->get("Name") | Theme name as given in theme's style.css | |
|
| 45 | + * | theme-uri | $theme_info->get("ThemeURI") | The path to the theme's directory | |
|
| 46 | + * | theme-description | $theme_info->get("Description") | The description of the theme | |
|
| 47 | + * | theme-author | $theme_info->get("Author") | The theme's author | |
|
| 48 | + * | theme-author_uri | $theme_info->get("AuthorURI") | The website of the theme author | |
|
| 49 | + * | theme-version | $theme_info->get("Version") | The version of the theme | |
|
| 50 | + * | theme-template | $theme_info->get("Template") | The folder name of the current theme | |
|
| 51 | + * | theme-status | $theme_info->get("Status") | If the theme is published | |
|
| 52 | + * | theme-tags | $theme_info->get("Tags") | Tags used to describe the theme | |
|
| 53 | + * | theme-text_domain | $theme_info->get("TextDomain") | The text domain used in the theme for translation purposes | |
|
| 54 | + * | theme-domain_path | $theme_info->get("DomainPath") | Path to the theme translation files | |
|
| 55 | + * |
|
| 56 | + * @version 1.0.0 |
|
| 57 | + */ |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Class Redux_Shortcodes |
|
| 61 | + */ |
|
| 62 | + class Redux_Shortcodes { |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Redux_Shortcodes constructor. |
|
| 66 | + */ |
|
| 67 | + public function __construct() { |
|
| 68 | + if ( ! shortcode_exists( 'bloginfo' ) ) { |
|
| 69 | + add_shortcode( 'bloginfo', array( $this, 'blog_info' ) ); |
|
| 70 | + } else { |
|
| 71 | + add_shortcode( 'redux_bloginfo', array( $this, 'blog_info' ) ); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + if ( ! shortcode_exists( 'themeinfo' ) ) { |
|
| 75 | + add_shortcode( 'themeinfo', array( $this, 'theme_info' ) ); |
|
| 76 | + } else { |
|
| 77 | + add_shortcode( 'redux_themeinfo', array( $this, 'theme_info' ) ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + if ( ! shortcode_exists( 'date' ) ) { |
|
| 81 | + add_shortcode( 'date', array( $this, 'date' ) ); |
|
| 82 | + } else { |
|
| 83 | + add_shortcode( 'redux_date', array( $this, 'date' ) ); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Get shortcode data. |
|
| 89 | + * |
|
| 90 | + * @param array|string $atts Attributes. |
|
| 91 | + * @param string|null $content Content. |
|
| 92 | + * |
|
| 93 | + * @return bool|string|null |
|
| 94 | + */ |
|
| 95 | + public function blog_info( $atts = array(), ?string $content = null ) { |
|
| 96 | + if ( ! is_array( $atts ) ) { |
|
| 97 | + $atts = array(); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $content = sanitize_text_field( $content ); |
|
| 101 | + $atts = array_map( 'sanitize_text_field', wp_unslash( $atts ) ); |
|
| 102 | + |
|
| 103 | + if ( ! empty( $content ) && ! isset( $atts['data'] ) ) { |
|
| 104 | + $atts['data'] = $content; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + switch ( $atts['data'] ) { |
|
| 108 | + case 'stylesheet_directory': |
|
| 109 | + case 'child_template_directory': |
|
| 110 | + return get_stylesheet_directory(); |
|
| 111 | + case 'parent_template_url': |
|
| 112 | + return get_template_directory_uri(); |
|
| 113 | + case 'child_template_url': |
|
| 114 | + case 'template_url': |
|
| 115 | + return get_stylesheet_directory_uri(); |
|
| 116 | + case 'template_directory': |
|
| 117 | + return get_template_directory(); |
|
| 118 | + case 'text_direction': |
|
| 119 | + case 'text_direction_bool': |
|
| 120 | + case 'text_direction_boolean': |
|
| 121 | + return is_rtl(); |
|
| 122 | + case 'is_multisite': |
|
| 123 | + return is_multisite(); |
|
| 124 | + case 'url': |
|
| 125 | + return esc_url( home_url() ); |
|
| 126 | + case 'root_url': |
|
| 127 | + return esc_url( site_url() ); |
|
| 128 | + case 'stylesheet_url': |
|
| 129 | + return esc_url( get_stylesheet_uri() ); |
|
| 130 | + case 'logout_url': |
|
| 131 | + return esc_url( wp_logout_url() ); |
|
| 132 | + case 'login_url': |
|
| 133 | + return esc_url( wp_login_url() ); |
|
| 134 | + case 'register_url': |
|
| 135 | + return esc_url( wp_registration_url() ); |
|
| 136 | + case 'lostpassword_url': |
|
| 137 | + case 'lost_password_url': |
|
| 138 | + return esc_url( wp_lostpassword_url() ); |
|
| 139 | + default: |
|
| 140 | + return get_bloginfo( $atts['data'] ); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Get theme info. |
|
| 146 | + * |
|
| 147 | + * @param array|string $atts Attributes. |
|
| 148 | + * @param string|null $content Content. |
|
| 149 | + * |
|
| 150 | + * @return array|bool|string |
|
| 151 | + */ |
|
| 152 | + public function theme_info( array $atts = array(), ?string $content = null ) { |
|
| 153 | + if ( ! is_array( $atts ) ) { |
|
| 154 | + $atts = array(); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + $content = sanitize_text_field( $content ); |
|
| 158 | + $atts = array_map( 'sanitize_text_field', wp_unslash( $atts ) ); |
|
| 159 | + |
|
| 160 | + if ( ! empty( $content ) && ! isset( $atts['data'] ) ) { |
|
| 161 | + $atts['data'] = $content; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + if ( empty( $this->theme_info ) ) { |
|
| 165 | + $this->theme_info = wp_get_theme(); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $keys = array( |
|
| 169 | + 'name' => 'Name', |
|
| 170 | + 'themeuri' => 'ThemeURI', |
|
| 171 | + 'theme_uri' => 'ThemeURI', |
|
| 172 | + 'description' => 'Description', |
|
| 173 | + 'author' => 'Author', |
|
| 174 | + 'authoruri' => 'AuthorURI', |
|
| 175 | + 'author_uri' => 'AuthorURI', |
|
| 176 | + 'version' => 'Version', |
|
| 177 | + 'template' => 'Template', |
|
| 178 | + 'status' => 'Status', |
|
| 179 | + 'tags' => 'Tags', |
|
| 180 | + 'textdomain' => 'TextDomain', |
|
| 181 | + 'text_domain' => 'TextDomain', |
|
| 182 | + 'domainpath' => 'DomainPath', |
|
| 183 | + 'domain_path' => 'DomainPath', |
|
| 184 | + 'is_child' => 'is_child', |
|
| 185 | + ); |
|
| 186 | + |
|
| 187 | + $atts['data'] = $keys[ strtolower( $atts['data'] ) ]; |
|
| 188 | + |
|
| 189 | + switch ( $atts['data'] ) { |
|
| 190 | + case 'is_child': |
|
| 191 | + return Redux_Helpers::is_child_theme( get_template_directory() ); |
|
| 192 | + default: |
|
| 193 | + $return = $this->theme_info->get( $atts['data'] ); |
|
| 194 | + |
|
| 195 | + if ( is_array( $return ) ) { |
|
| 196 | + $return = implode( ', ', $return ); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $return; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Get date info. |
|
| 205 | + * |
|
| 206 | + * @param array|string $atts Attributes. |
|
| 207 | + * @param string|null $content Content. |
|
| 208 | + * |
|
| 209 | + * @return false|string |
|
| 210 | + */ |
|
| 211 | + public function date( $atts = array(), ?string $content = null ) { |
|
| 212 | + if ( ! is_array( $atts ) ) { |
|
| 213 | + $atts = array(); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + $content = sanitize_text_field( $content ); |
|
| 217 | + $atts = array_map( 'sanitize_text_field', wp_unslash( $atts ) ); |
|
| 218 | + |
|
| 219 | + if ( ! empty( $content ) && ! isset( $atts['data'] ) ) { |
|
| 220 | + $atts['data'] = $content; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + if ( empty( $atts['data'] ) ) { |
|
| 224 | + $atts['data'] = 'Y'; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + return gmdate( $atts['data'] ); |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | 230 | } |
@@ -14,1184 +14,1184 @@ discard block |
||
| 14 | 14 | // Don't duplicate me! |
| 15 | 15 | if ( ! class_exists( 'Redux_Extension_Metaboxes', false ) ) { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Main Redux_Extension_Metaboxes class |
|
| 19 | - * |
|
| 20 | - * @since 1.0.0 |
|
| 21 | - */ |
|
| 22 | - class Redux_Extension_Metaboxes extends Redux_Extension_Abstract { |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Extension version. |
|
| 26 | - * |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - public static $version = '4.2.0'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Extension friendly name. |
|
| 33 | - * |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - public string $extension_name = 'Metaboxes'; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Boxes array. |
|
| 40 | - * |
|
| 41 | - * @var array|null |
|
| 42 | - */ |
|
| 43 | - public ?array $boxes = array(); |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Post types array. |
|
| 47 | - * |
|
| 48 | - * @var array|null |
|
| 49 | - */ |
|
| 50 | - public ?array $post_types = array(); |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Post type. |
|
| 54 | - * |
|
| 55 | - * @var string|null |
|
| 56 | - */ |
|
| 57 | - public ?string $post_type; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Sections array. |
|
| 61 | - * |
|
| 62 | - * @var array|null |
|
| 63 | - */ |
|
| 64 | - public ?array $orig_args; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Sections array. |
|
| 68 | - * |
|
| 69 | - * @var array|null |
|
| 70 | - */ |
|
| 71 | - public ?array $sections = array(); |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * CSS output array. |
|
| 75 | - * |
|
| 76 | - * @var array|null |
|
| 77 | - */ |
|
| 78 | - public ?array $output = array(); |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Options array. |
|
| 82 | - * |
|
| 83 | - * @var array |
|
| 84 | - */ |
|
| 85 | - public array $options = array(); |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Parent options array. |
|
| 89 | - * |
|
| 90 | - * @var array |
|
| 91 | - */ |
|
| 92 | - public array $parent_options = array(); |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Parent defaults array. |
|
| 96 | - * |
|
| 97 | - * @var array |
|
| 98 | - */ |
|
| 99 | - public array $parent_defaults = array(); |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Post type fields array. |
|
| 103 | - * |
|
| 104 | - * @var array |
|
| 105 | - */ |
|
| 106 | - public array $post_type_fields = array(); |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Options defaults array. |
|
| 110 | - * |
|
| 111 | - * @var array |
|
| 112 | - */ |
|
| 113 | - public array $options_defaults = array(); |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Replace array. |
|
| 117 | - * |
|
| 118 | - * @var array |
|
| 119 | - */ |
|
| 120 | - public array $to_replace = array(); |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Meta data array. |
|
| 124 | - * |
|
| 125 | - * @var array |
|
| 126 | - */ |
|
| 127 | - public array $meta = array(); |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Post ID. |
|
| 131 | - * |
|
| 132 | - * @var null|int |
|
| 133 | - */ |
|
| 134 | - public ?int $post_id = 0; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Base URI. |
|
| 138 | - * |
|
| 139 | - * @var string|null |
|
| 140 | - */ |
|
| 141 | - public ?string $base_url; |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * WP_Links array. |
|
| 145 | - * |
|
| 146 | - * @var array |
|
| 147 | - */ |
|
| 148 | - public array $wp_links = array(); |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Notices. |
|
| 152 | - * |
|
| 153 | - * @var array |
|
| 154 | - */ |
|
| 155 | - private array $notices = array(); |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * ReduxFramework_extension_metaboxes constructor. |
|
| 159 | - * |
|
| 160 | - * @param object $redux ReduxFramework object. |
|
| 161 | - */ |
|
| 162 | - public function __construct( $redux ) { |
|
| 163 | - global $pagenow; |
|
| 164 | - |
|
| 165 | - parent::__construct( $redux, __FILE__ ); |
|
| 166 | - |
|
| 167 | - $this->parent->extensions['metaboxes'] = $this; |
|
| 168 | - |
|
| 169 | - $this->extension_dir = trailingslashit( str_replace( '\\', '/', __DIR__ ) ); |
|
| 170 | - $this->extension_url = site_url( str_replace( trailingslashit( str_replace( '\\', '/', ABSPATH ) ), '', $this->extension_dir ) ); |
|
| 171 | - |
|
| 172 | - // Only run metaboxes on the pages/posts, not the front-end. |
|
| 173 | - // The DOING_AJAX check allows for redux_post_meta to work inside |
|
| 174 | - // AJAX calls. - kp. |
|
| 175 | - if ( 'post-new.php' !== $pagenow && 'post.php' !== $pagenow ) { |
|
| 176 | - if ( is_admin() ) { |
|
| 177 | - if ( defined( 'DOING_AJAX' ) && ! DOING_AJAX ) { |
|
| 178 | - return; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - return; |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - if ( 'wp-cron.php' === $pagenow || 'wp-comments-post.php' === $pagenow ) { |
|
| 186 | - return; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // Must not update the DB when just updating metaboxes. Sheesh. |
|
| 190 | - if ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) { |
|
| 191 | - $this->parent->never_save_to_db = true; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - include_once Redux_Core::$dir . 'inc/extensions/metaboxes/redux-metaboxes-helpers.php'; |
|
| 195 | - |
|
| 196 | - // phpcs:ignore Generic.Strings.UnnecessaryStringConcat |
|
| 197 | - add_action( 'add_' . 'meta_' . 'boxes', array( $this, 'add' ) ); |
|
| 198 | - add_action( 'save_post', array( $this, 'meta_boxes_save' ), 1, 2 ); |
|
| 199 | - add_action( 'pre_post_update', array( $this, 'pre_post_update' ) ); |
|
| 200 | - add_action( 'admin_notices', array( $this, 'meta_boxes_show_errors' ), 0 ); |
|
| 201 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ), 20 ); |
|
| 202 | - |
|
| 203 | - // Global variable overrides for within loops. |
|
| 204 | - add_action( 'the_post', array( $this, 'loop_start' ), 0 ); |
|
| 205 | - add_action( 'loop_end', array( $this, 'loop_end' ), 0 ); |
|
| 206 | - |
|
| 207 | - $this->init(); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Added class names to metabox DIV. |
|
| 212 | - * |
|
| 213 | - * @param array $classes Class array. |
|
| 214 | - * |
|
| 215 | - * @return array |
|
| 216 | - */ |
|
| 217 | - public function add_box_classes( array $classes ): array { |
|
| 218 | - $classes[] = 'redux-metabox'; |
|
| 219 | - $classes[] = 'redux-' . $this->parent->args['opt_name']; |
|
| 220 | - |
|
| 221 | - if ( '' !== $this->parent->args['class'] ) { |
|
| 222 | - $classes[] = $this->parent->args['class']; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - return $classes; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Class init. |
|
| 230 | - */ |
|
| 231 | - public function init() { |
|
| 232 | - global $pagenow; |
|
| 233 | - |
|
| 234 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 235 | - $this->boxes = apply_filters( 'redux/metaboxes/' . $this->parent->args['opt_name'] . '/boxes', $this->boxes, $this->parent->args['opt_name'] ); |
|
| 236 | - |
|
| 237 | - if ( empty( $this->boxes ) && class_exists( 'Redux_Metaboxes' ) ) { |
|
| 238 | - $this->boxes = Redux_Metaboxes::construct_boxes( $this->parent->args['opt_name'] ); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - if ( empty( $this->boxes ) || ! is_array( $this->boxes ) ) { |
|
| 242 | - return; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - if ( isset( Redux_Core::$server['HTTP_HOST'] ) && isset( Redux_Core::$server['REQUEST_URI'] ) ) { |
|
| 246 | - $this->base_url = ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( wp_unslash( Redux_Core::$server['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( Redux_Core::$server['REQUEST_URI'] ) ); // Safe & Reliable. |
|
| 247 | - $this->post_id = $this->url_to_postid( ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( wp_unslash( Redux_Core::$server['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( Redux_Core::$server['REQUEST_URI'] ) ) ); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - if ( is_admin() && isset( $_GET['post_type'] ) && ! empty( $_GET['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 251 | - $this->post_type = sanitize_text_field( wp_unslash( $_GET['post_type'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 252 | - } else { |
|
| 253 | - $this->post_type = get_post_type( $this->post_id ); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - foreach ( $this->boxes as $bk => $box ) { |
|
| 257 | - |
|
| 258 | - // If the post-ids for this box are set, we're limiting to the current post id. |
|
| 259 | - if ( ! empty( $box['post_ids'] ) ) { |
|
| 260 | - if ( ! is_array( $box['post_ids'] ) ) { |
|
| 261 | - $box['post_ids'] = array( $box['post_ids'] ); |
|
| 262 | - } |
|
| 263 | - if ( ! in_array( $this->post_id, $box['post_ids'], true ) ) { |
|
| 264 | - continue; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - if ( ! empty( $box['sections'] ) ) { |
|
| 269 | - $this->sections = wp_parse_args( $this->sections, $box['sections'] ); |
|
| 270 | - |
|
| 271 | - $this->post_types = wp_parse_args( $this->post_types, $box['post_types'] ); |
|
| 272 | - |
|
| 273 | - // Checking to override the parent variables. |
|
| 274 | - $add_field = false; |
|
| 275 | - |
|
| 276 | - foreach ( $box['post_types'] as $type ) { |
|
| 277 | - if ( $this->post_type === $type ) { |
|
| 278 | - $add_field = true; |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // Replacing all the fields. |
|
| 283 | - if ( $add_field || ( ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) || ( ! is_admin() ) ) ) { |
|
| 284 | - $run_hooks = true; |
|
| 285 | - |
|
| 286 | - $box_id = 'redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id']; |
|
| 287 | - |
|
| 288 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 289 | - do_action( 'redux/' . $this->parent->args['opt_name'] . '/extensions/metabox/init', $this, $box ); |
|
| 290 | - |
|
| 291 | - if ( isset( $box['page_template'] ) && 'page' === $this->post_type ) { |
|
| 292 | - if ( ! is_array( $box['page_template'] ) ) { |
|
| 293 | - $box['page_template'] = array( $box['page_template'] ); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - $this->wp_links[ $box_id ]['page_template'] = isset( $this->wp_links[ $box_id ]['page_template'] ) ? wp_parse_args( $this->wp_links[ $box_id ]['page_template'], $box['page_template'] ) : $box['page_template']; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - if ( isset( $box['post_format'] ) && ( in_array( $this->post_type, $this->post_types, true ) || '' === $this->post_type || false === $this->post_type ) ) { |
|
| 300 | - if ( ! is_array( $box['post_format'] ) ) { |
|
| 301 | - $box['post_format'] = array( $box['post_format'] ); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - $this->wp_links[ $box_id ]['post_format'] = isset( $this->wp_links[ $box_id ]['post_format'] ) ? wp_parse_args( $this->wp_links[ $box_id ]['post_format'], $box['post_format'] ) : $box['post_format']; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - $this->meta[ $this->post_id ] = $this->get_meta( $this->post_id ); |
|
| 308 | - |
|
| 309 | - foreach ( $box['sections'] as $sk => $section ) { |
|
| 310 | - if ( ! empty( $section['fields'] ) ) { |
|
| 311 | - foreach ( $section['fields'] as $fk => $field ) { |
|
| 312 | - if ( ! isset( $field['class'] ) ) { |
|
| 313 | - $field['class'] = ''; |
|
| 314 | - |
|
| 315 | - $this->boxes[ $bk ]['sections'][ $sk ]['fields'][ $fk ] = $field; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - if ( $add_field || ( ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) || ( ! is_admin() ) ) ) { |
|
| 319 | - if ( empty( $field['id'] ) ) { |
|
| 320 | - continue; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - if ( isset( $field['default'] ) ) { |
|
| 324 | - $this->options_defaults[ $field['id'] ] = $field['default']; |
|
| 325 | - } else { |
|
| 326 | - $this->options_defaults[ $field['id'] ] = $this->field_default( $field ); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - foreach ( $box['post_types'] as $type ) { |
|
| 330 | - $this->post_type_fields[ $type ][ $field['id'] ] = 1; |
|
| 331 | - |
|
| 332 | - if ( 'repeater' === $field['type'] ) { |
|
| 333 | - foreach ( $field['fields'] as $val ) { |
|
| 334 | - $this->post_type_fields[ $type ][ $val['id'] ] = 1; |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - if ( ! empty( $field['output'] ) ) { |
|
| 340 | - $this->output[ $field['id'] ] = isset( $this->output[ $field['id'] ] ) ? array_merge( $field['output'], $this->output[ $field['id'] ] ) : $field['output']; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - // Detect what field types are being used. |
|
| 344 | - if ( ! isset( $this->parent->fields[ $field['type'] ][ $field['id'] ] ) ) { |
|
| 345 | - $this->parent->fields[ $field['type'] ][ $field['id'] ] = 1; |
|
| 346 | - } else { |
|
| 347 | - $this->parent->fields[ $field['type'] ] = array( $field['id'] => 1 ); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - if ( isset( $this->options_defaults[ $field['id'] ] ) ) { |
|
| 351 | - $this->to_replace[ $field['id'] ] = $field; |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - if ( ! isset( $this->parent->options[ $field['id'] ] ) ) { |
|
| 356 | - $this->parent->sections[ ( count( $this->parent->sections ) - 1 ) ]['fields'][] = $field; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - if ( ! isset( $this->meta[ $this->post_id ][ $field['id'] ] ) ) { |
|
| 360 | - $this->meta[ $this->post_id ][ $field['id'] ] = $this->options_defaults[ $field['id'] ]; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - // Only override if it exists, and it's not the default. |
|
| 364 | - // phpcs:ignore Squiz.PHP.CommentedOutCode |
|
| 365 | - // if ( isset( $this->meta[ $this->post_id ][ $field['id'] ] ) && isset( $field['default'] ) && $this->meta[ $this->post_id ][ $field['id'] ] === $field['default'] ) { |
|
| 366 | - // unset($this->meta[$this->post_id][$field['id']]); |
|
| 367 | - // } . |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - if ( isset( $run_hooks ) && true === $run_hooks ) { |
|
| 376 | - $this->parent_options = array(); |
|
| 377 | - |
|
| 378 | - if ( ! empty( $this->to_replace ) ) { |
|
| 379 | - foreach ( $this->to_replace as $id => $field ) { |
|
| 380 | - |
|
| 381 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 382 | - add_filter( "redux/options/{$this->parent->args['opt_name']}/field/$id/register", array( $this, 'replace_field' ) ); |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - add_filter( "redux/options/{$this->parent->args['opt_name']}/options", array( $this, 'override_options' ) ); |
|
| 387 | - add_filter( "redux/field/{$this->parent->args['opt_name']}/_can_output_css", array( $this, 'override_can_output_css' ) ); |
|
| 388 | - add_filter( "redux/field/{$this->parent->args['opt_name']}/output_css", array( $this, 'output_css' ) ); |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Replace Field. |
|
| 394 | - * |
|
| 395 | - * @param array $field Field array. |
|
| 396 | - * |
|
| 397 | - * @return mixed |
|
| 398 | - */ |
|
| 399 | - public function replace_field( array $field ) { |
|
| 400 | - if ( isset( $this->to_replace[ $field['id'] ] ) ) { |
|
| 401 | - $field = $this->to_replace[ $field['id'] ]; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - return $field; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * Override CSS output. |
|
| 409 | - * |
|
| 410 | - * @param array $field Field array. |
|
| 411 | - * |
|
| 412 | - * @return array |
|
| 413 | - */ |
|
| 414 | - public function override_can_output_css( array $field ): array { |
|
| 415 | - if ( isset( $this->output[ $field['id'] ] ) ) { |
|
| 416 | - $field['force_output'] = true; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - return $field; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Output CSS. |
|
| 424 | - * |
|
| 425 | - * @param array $field Field array. |
|
| 426 | - * |
|
| 427 | - * @return array |
|
| 428 | - */ |
|
| 429 | - public function output_css( array $field ): array { |
|
| 430 | - if ( isset( $this->output[ $field['id'] ] ) ) { |
|
| 431 | - $field['output'] = $this->output[ $field['id'] ]; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - return $field; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Make sure the defaults are the defaults |
|
| 439 | - * |
|
| 440 | - * @param array $options Options array. |
|
| 441 | - * |
|
| 442 | - * @return array |
|
| 443 | - */ |
|
| 444 | - public function override_options( array $options ): array { |
|
| 445 | - $this->parent->default_values(); |
|
| 446 | - $this->parent_defaults = $this->parent->options_defaults; |
|
| 447 | - |
|
| 448 | - $meta = $this->get_meta( $this->post_id ); |
|
| 449 | - $data = wp_parse_args( $meta, $this->options_defaults ); |
|
| 450 | - |
|
| 451 | - foreach ( $data as $key => $value ) { |
|
| 452 | - if ( isset( $meta[ $key ] ) && '' !== $meta[ $key ] ) { |
|
| 453 | - $data[ $key ] = $meta[ $key ]; |
|
| 454 | - continue; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - if ( isset( $options[ $key ] ) ) { |
|
| 458 | - $data[ $key ] = $options[ $key ]; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - $this->parent->options_defaults = wp_parse_args( $this->options_defaults, $this->parent->options_defaults ); |
|
| 463 | - |
|
| 464 | - return wp_parse_args( $data, $options ); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Loop start. |
|
| 469 | - * |
|
| 470 | - * @param mixed $the_post WP_Post object. |
|
| 471 | - * |
|
| 472 | - * @return array|void |
|
| 473 | - */ |
|
| 474 | - public function loop_start( $the_post = array() ) { |
|
| 475 | - if ( is_admin() ) { |
|
| 476 | - return $the_post; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - if ( isset( $the_post ) && is_array( $the_post ) ) { |
|
| 480 | - global $post; |
|
| 481 | - $the_post = $post; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - if ( isset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ) ) { |
|
| 485 | - $GLOBALS[ $this->parent->args['global_variable'] ] = $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ]; |
|
| 486 | - unset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - // Override these values if they differ from the admin panel defaults. ;) . |
|
| 490 | - if ( in_array( $the_post->post_type, $this->post_types, true ) ) { |
|
| 491 | - $meta = $this->get_meta( $the_post->ID ); |
|
| 492 | - if ( empty( $meta ) ) { |
|
| 493 | - return; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - // Backup the args. |
|
| 497 | - $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] = $GLOBALS[ $this->parent->args['global_variable'] ]; |
|
| 498 | - $GLOBALS[ $this->parent->args['global_variable'] ] = wp_parse_args( $meta, $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ); |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Loop end. |
|
| 504 | - */ |
|
| 505 | - public function loop_end() { |
|
| 506 | - if ( isset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ) ) { |
|
| 507 | - $GLOBALS[ $this->parent->args['global_variable'] ] = $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ]; |
|
| 508 | - |
|
| 509 | - unset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ); |
|
| 510 | - } |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * Enqueue fields. |
|
| 515 | - */ |
|
| 516 | - public function enqueue() { |
|
| 517 | - global $pagenow; |
|
| 518 | - |
|
| 519 | - $types = array(); |
|
| 520 | - |
|
| 521 | - // Enqueue CSS. |
|
| 522 | - foreach ( $this->boxes as $key => $box ) { |
|
| 523 | - if ( empty( $box['sections'] ) ) { |
|
| 524 | - continue; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - if ( isset( $box['post_types'] ) ) { |
|
| 528 | - $types = array_merge( $box['post_types'], $types ); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - if ( ! empty( $box['post_types'] ) ) { |
|
| 532 | - if ( ! is_array( $box['post_types'] ) ) { |
|
| 533 | - $box['post_types'] = array( $box['post_types'] ); |
|
| 534 | - $this->boxes[ $key ]['post_types'] = $box['post_types']; |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - if ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) { |
|
| 540 | - global $post; |
|
| 541 | - |
|
| 542 | - if ( in_array( $post->post_type, $types, true ) ) { |
|
| 543 | - $this->parent->transients = get_transient( $this->parent->args['opt_name'] . '-transients-metaboxes' ); |
|
| 544 | - $this->parent->transients_check = $this->parent->transients; |
|
| 545 | - |
|
| 546 | - if ( isset( $this->parent->transients['notices'] ) ) { |
|
| 547 | - $this->notices = $this->parent->transients['notices']; |
|
| 548 | - $this->parent->transients['last_save_mode'] = 'metaboxes'; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - delete_transient( $this->parent->args['opt_name'] . '-transients-metaboxes' ); |
|
| 552 | - $this->parent->enqueue_class->init(); |
|
| 553 | - |
|
| 554 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 555 | - do_action( "redux/metaboxes/{$this->parent->args['opt_name']}/enqueue" ); |
|
| 556 | - |
|
| 557 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 558 | - do_action( "redux/{$this->parent->args['opt_name']}/extensions/metaboxes/enqueue" ); |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * Redux metaboxes CSS |
|
| 562 | - * filter 'redux/page/{opt_name}/enqueue/redux-extension-metaboxes-css' |
|
| 563 | - */ |
|
| 564 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 565 | - wp_enqueue_style( |
|
| 566 | - 'redux-extension-metaboxes', |
|
| 567 | - apply_filters( "redux/metaboxes/{$this->parent->args['opt_name']}/enqueue/redux-extension-metaboxes-css", $this->extension_url . 'redux-extension-metaboxes.css' ), // phpcs:ignore: WordPress.NamingConventions.ValidHookName |
|
| 568 | - array(), |
|
| 569 | - self::$version |
|
| 570 | - ); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - /** |
|
| 574 | - * Redux metaboxes JS |
|
| 575 | - * filter 'redux/page/{opt_name}/enqueue/redux-extension-metaboxes-js |
|
| 576 | - */ |
|
| 577 | - wp_enqueue_script( |
|
| 578 | - 'redux-extension-metaboxes', |
|
| 579 | - apply_filters( "redux/metaboxes/{$this->parent->args['opt_name']}/enqueue/redux-extension-metaboxes-js", $this->extension_url . 'redux-extension-metaboxes' . Redux_Functions::isMin() . '.js' ), // phpcs:ignore: WordPress.NamingConventions.ValidHookName |
|
| 580 | - array( 'jquery', 'redux-js' ), |
|
| 581 | - self::$version, |
|
| 582 | - true |
|
| 583 | - ); |
|
| 584 | - |
|
| 585 | - // Values used by the javascript. |
|
| 586 | - wp_localize_script( |
|
| 587 | - 'redux-extension-metaboxes', |
|
| 588 | - 'reduxMetaboxes', |
|
| 589 | - $this->wp_links |
|
| 590 | - ); |
|
| 591 | - |
|
| 592 | - wp_localize_script( |
|
| 593 | - 'redux-extension-metaboxes', |
|
| 594 | - 'reduxMetaboxesPageTemplate', |
|
| 595 | - array( |
|
| 596 | - '_wp_page_template' => get_post_meta( get_the_ID(), '_wp_page_template', true ), |
|
| 597 | - ) |
|
| 598 | - ); |
|
| 599 | - } |
|
| 600 | - } |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - /* Post URLs to IDs function, supports custom post types - borrowed and modified from url_to_postid() in wp-includes/rewrite.php */ |
|
| 604 | - |
|
| 605 | - // Taken from http://betterwp.net/wordpress-tips/url_to_postid-for-custom-post-types/ |
|
| 606 | - // Customized to work with non-rewrite URLs |
|
| 607 | - // Modified by Dovy Paukstys (@dovy) of Redux Framework. |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * URL to PostID. |
|
| 611 | - * |
|
| 612 | - * @param string $url URL. |
|
| 613 | - * |
|
| 614 | - * @return int|mixed|void |
|
| 615 | - */ |
|
| 616 | - private function url_to_postid( string $url ) { |
|
| 617 | - global $wp_rewrite, $pagenow; |
|
| 618 | - |
|
| 619 | - if ( ! empty( $this->post_id ) ) { |
|
| 620 | - return $this->post_id; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - if ( isset( $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 624 | - $post = (int) sanitize_text_field( wp_unslash( $_GET['post'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 625 | - |
|
| 626 | - if ( ! empty( $post ) ) { |
|
| 627 | - return $post; |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - if ( 'post-new.php' === $pagenow || 'wp-login.php' === $pagenow ) { |
|
| 632 | - return; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - if ( is_admin() && 'post.php' === $pagenow && isset( $_POST['post_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 636 | - $post_id = sanitize_text_field( wp_unslash( $_POST['post_ID'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 637 | - |
|
| 638 | - if ( ! empty( $post_id ) && is_numeric( $post_id ) ) { |
|
| 639 | - return $post_id; |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - $post_id = url_to_postid( $url ); |
|
| 644 | - |
|
| 645 | - if ( isset( $post_id ) && '' !== (string) $post_id && 0 !== $post_id ) { |
|
| 646 | - return $post_id; |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - // First, check to see if there is a 'p=N' or 'page_id=N' to match against. |
|
| 650 | - if ( preg_match( '#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values ) ) { |
|
| 651 | - $id = absint( $values[2] ); |
|
| 652 | - if ( $id ) { |
|
| 653 | - return $id; |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - // Check to see if we are using rewrite rules. |
|
| 658 | - if ( isset( $wp_rewrite ) ) { |
|
| 659 | - $rewrite = $wp_rewrite->wp_rewrite_rules(); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options. |
|
| 663 | - if ( empty( $rewrite ) ) { |
|
| 664 | - if ( ! empty( $_GET ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 665 | - |
|
| 666 | - /************************************************************************ |
|
| 17 | + /** |
|
| 18 | + * Main Redux_Extension_Metaboxes class |
|
| 19 | + * |
|
| 20 | + * @since 1.0.0 |
|
| 21 | + */ |
|
| 22 | + class Redux_Extension_Metaboxes extends Redux_Extension_Abstract { |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Extension version. |
|
| 26 | + * |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + public static $version = '4.2.0'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Extension friendly name. |
|
| 33 | + * |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + public string $extension_name = 'Metaboxes'; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Boxes array. |
|
| 40 | + * |
|
| 41 | + * @var array|null |
|
| 42 | + */ |
|
| 43 | + public ?array $boxes = array(); |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Post types array. |
|
| 47 | + * |
|
| 48 | + * @var array|null |
|
| 49 | + */ |
|
| 50 | + public ?array $post_types = array(); |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Post type. |
|
| 54 | + * |
|
| 55 | + * @var string|null |
|
| 56 | + */ |
|
| 57 | + public ?string $post_type; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Sections array. |
|
| 61 | + * |
|
| 62 | + * @var array|null |
|
| 63 | + */ |
|
| 64 | + public ?array $orig_args; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Sections array. |
|
| 68 | + * |
|
| 69 | + * @var array|null |
|
| 70 | + */ |
|
| 71 | + public ?array $sections = array(); |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * CSS output array. |
|
| 75 | + * |
|
| 76 | + * @var array|null |
|
| 77 | + */ |
|
| 78 | + public ?array $output = array(); |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Options array. |
|
| 82 | + * |
|
| 83 | + * @var array |
|
| 84 | + */ |
|
| 85 | + public array $options = array(); |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Parent options array. |
|
| 89 | + * |
|
| 90 | + * @var array |
|
| 91 | + */ |
|
| 92 | + public array $parent_options = array(); |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Parent defaults array. |
|
| 96 | + * |
|
| 97 | + * @var array |
|
| 98 | + */ |
|
| 99 | + public array $parent_defaults = array(); |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Post type fields array. |
|
| 103 | + * |
|
| 104 | + * @var array |
|
| 105 | + */ |
|
| 106 | + public array $post_type_fields = array(); |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Options defaults array. |
|
| 110 | + * |
|
| 111 | + * @var array |
|
| 112 | + */ |
|
| 113 | + public array $options_defaults = array(); |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Replace array. |
|
| 117 | + * |
|
| 118 | + * @var array |
|
| 119 | + */ |
|
| 120 | + public array $to_replace = array(); |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Meta data array. |
|
| 124 | + * |
|
| 125 | + * @var array |
|
| 126 | + */ |
|
| 127 | + public array $meta = array(); |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Post ID. |
|
| 131 | + * |
|
| 132 | + * @var null|int |
|
| 133 | + */ |
|
| 134 | + public ?int $post_id = 0; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Base URI. |
|
| 138 | + * |
|
| 139 | + * @var string|null |
|
| 140 | + */ |
|
| 141 | + public ?string $base_url; |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * WP_Links array. |
|
| 145 | + * |
|
| 146 | + * @var array |
|
| 147 | + */ |
|
| 148 | + public array $wp_links = array(); |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Notices. |
|
| 152 | + * |
|
| 153 | + * @var array |
|
| 154 | + */ |
|
| 155 | + private array $notices = array(); |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * ReduxFramework_extension_metaboxes constructor. |
|
| 159 | + * |
|
| 160 | + * @param object $redux ReduxFramework object. |
|
| 161 | + */ |
|
| 162 | + public function __construct( $redux ) { |
|
| 163 | + global $pagenow; |
|
| 164 | + |
|
| 165 | + parent::__construct( $redux, __FILE__ ); |
|
| 166 | + |
|
| 167 | + $this->parent->extensions['metaboxes'] = $this; |
|
| 168 | + |
|
| 169 | + $this->extension_dir = trailingslashit( str_replace( '\\', '/', __DIR__ ) ); |
|
| 170 | + $this->extension_url = site_url( str_replace( trailingslashit( str_replace( '\\', '/', ABSPATH ) ), '', $this->extension_dir ) ); |
|
| 171 | + |
|
| 172 | + // Only run metaboxes on the pages/posts, not the front-end. |
|
| 173 | + // The DOING_AJAX check allows for redux_post_meta to work inside |
|
| 174 | + // AJAX calls. - kp. |
|
| 175 | + if ( 'post-new.php' !== $pagenow && 'post.php' !== $pagenow ) { |
|
| 176 | + if ( is_admin() ) { |
|
| 177 | + if ( defined( 'DOING_AJAX' ) && ! DOING_AJAX ) { |
|
| 178 | + return; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + return; |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + if ( 'wp-cron.php' === $pagenow || 'wp-comments-post.php' === $pagenow ) { |
|
| 186 | + return; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // Must not update the DB when just updating metaboxes. Sheesh. |
|
| 190 | + if ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) { |
|
| 191 | + $this->parent->never_save_to_db = true; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + include_once Redux_Core::$dir . 'inc/extensions/metaboxes/redux-metaboxes-helpers.php'; |
|
| 195 | + |
|
| 196 | + // phpcs:ignore Generic.Strings.UnnecessaryStringConcat |
|
| 197 | + add_action( 'add_' . 'meta_' . 'boxes', array( $this, 'add' ) ); |
|
| 198 | + add_action( 'save_post', array( $this, 'meta_boxes_save' ), 1, 2 ); |
|
| 199 | + add_action( 'pre_post_update', array( $this, 'pre_post_update' ) ); |
|
| 200 | + add_action( 'admin_notices', array( $this, 'meta_boxes_show_errors' ), 0 ); |
|
| 201 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ), 20 ); |
|
| 202 | + |
|
| 203 | + // Global variable overrides for within loops. |
|
| 204 | + add_action( 'the_post', array( $this, 'loop_start' ), 0 ); |
|
| 205 | + add_action( 'loop_end', array( $this, 'loop_end' ), 0 ); |
|
| 206 | + |
|
| 207 | + $this->init(); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Added class names to metabox DIV. |
|
| 212 | + * |
|
| 213 | + * @param array $classes Class array. |
|
| 214 | + * |
|
| 215 | + * @return array |
|
| 216 | + */ |
|
| 217 | + public function add_box_classes( array $classes ): array { |
|
| 218 | + $classes[] = 'redux-metabox'; |
|
| 219 | + $classes[] = 'redux-' . $this->parent->args['opt_name']; |
|
| 220 | + |
|
| 221 | + if ( '' !== $this->parent->args['class'] ) { |
|
| 222 | + $classes[] = $this->parent->args['class']; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + return $classes; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Class init. |
|
| 230 | + */ |
|
| 231 | + public function init() { |
|
| 232 | + global $pagenow; |
|
| 233 | + |
|
| 234 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 235 | + $this->boxes = apply_filters( 'redux/metaboxes/' . $this->parent->args['opt_name'] . '/boxes', $this->boxes, $this->parent->args['opt_name'] ); |
|
| 236 | + |
|
| 237 | + if ( empty( $this->boxes ) && class_exists( 'Redux_Metaboxes' ) ) { |
|
| 238 | + $this->boxes = Redux_Metaboxes::construct_boxes( $this->parent->args['opt_name'] ); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + if ( empty( $this->boxes ) || ! is_array( $this->boxes ) ) { |
|
| 242 | + return; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + if ( isset( Redux_Core::$server['HTTP_HOST'] ) && isset( Redux_Core::$server['REQUEST_URI'] ) ) { |
|
| 246 | + $this->base_url = ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( wp_unslash( Redux_Core::$server['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( Redux_Core::$server['REQUEST_URI'] ) ); // Safe & Reliable. |
|
| 247 | + $this->post_id = $this->url_to_postid( ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( wp_unslash( Redux_Core::$server['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( Redux_Core::$server['REQUEST_URI'] ) ) ); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + if ( is_admin() && isset( $_GET['post_type'] ) && ! empty( $_GET['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 251 | + $this->post_type = sanitize_text_field( wp_unslash( $_GET['post_type'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 252 | + } else { |
|
| 253 | + $this->post_type = get_post_type( $this->post_id ); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + foreach ( $this->boxes as $bk => $box ) { |
|
| 257 | + |
|
| 258 | + // If the post-ids for this box are set, we're limiting to the current post id. |
|
| 259 | + if ( ! empty( $box['post_ids'] ) ) { |
|
| 260 | + if ( ! is_array( $box['post_ids'] ) ) { |
|
| 261 | + $box['post_ids'] = array( $box['post_ids'] ); |
|
| 262 | + } |
|
| 263 | + if ( ! in_array( $this->post_id, $box['post_ids'], true ) ) { |
|
| 264 | + continue; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + if ( ! empty( $box['sections'] ) ) { |
|
| 269 | + $this->sections = wp_parse_args( $this->sections, $box['sections'] ); |
|
| 270 | + |
|
| 271 | + $this->post_types = wp_parse_args( $this->post_types, $box['post_types'] ); |
|
| 272 | + |
|
| 273 | + // Checking to override the parent variables. |
|
| 274 | + $add_field = false; |
|
| 275 | + |
|
| 276 | + foreach ( $box['post_types'] as $type ) { |
|
| 277 | + if ( $this->post_type === $type ) { |
|
| 278 | + $add_field = true; |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // Replacing all the fields. |
|
| 283 | + if ( $add_field || ( ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) || ( ! is_admin() ) ) ) { |
|
| 284 | + $run_hooks = true; |
|
| 285 | + |
|
| 286 | + $box_id = 'redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id']; |
|
| 287 | + |
|
| 288 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 289 | + do_action( 'redux/' . $this->parent->args['opt_name'] . '/extensions/metabox/init', $this, $box ); |
|
| 290 | + |
|
| 291 | + if ( isset( $box['page_template'] ) && 'page' === $this->post_type ) { |
|
| 292 | + if ( ! is_array( $box['page_template'] ) ) { |
|
| 293 | + $box['page_template'] = array( $box['page_template'] ); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + $this->wp_links[ $box_id ]['page_template'] = isset( $this->wp_links[ $box_id ]['page_template'] ) ? wp_parse_args( $this->wp_links[ $box_id ]['page_template'], $box['page_template'] ) : $box['page_template']; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + if ( isset( $box['post_format'] ) && ( in_array( $this->post_type, $this->post_types, true ) || '' === $this->post_type || false === $this->post_type ) ) { |
|
| 300 | + if ( ! is_array( $box['post_format'] ) ) { |
|
| 301 | + $box['post_format'] = array( $box['post_format'] ); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + $this->wp_links[ $box_id ]['post_format'] = isset( $this->wp_links[ $box_id ]['post_format'] ) ? wp_parse_args( $this->wp_links[ $box_id ]['post_format'], $box['post_format'] ) : $box['post_format']; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + $this->meta[ $this->post_id ] = $this->get_meta( $this->post_id ); |
|
| 308 | + |
|
| 309 | + foreach ( $box['sections'] as $sk => $section ) { |
|
| 310 | + if ( ! empty( $section['fields'] ) ) { |
|
| 311 | + foreach ( $section['fields'] as $fk => $field ) { |
|
| 312 | + if ( ! isset( $field['class'] ) ) { |
|
| 313 | + $field['class'] = ''; |
|
| 314 | + |
|
| 315 | + $this->boxes[ $bk ]['sections'][ $sk ]['fields'][ $fk ] = $field; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + if ( $add_field || ( ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) || ( ! is_admin() ) ) ) { |
|
| 319 | + if ( empty( $field['id'] ) ) { |
|
| 320 | + continue; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + if ( isset( $field['default'] ) ) { |
|
| 324 | + $this->options_defaults[ $field['id'] ] = $field['default']; |
|
| 325 | + } else { |
|
| 326 | + $this->options_defaults[ $field['id'] ] = $this->field_default( $field ); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + foreach ( $box['post_types'] as $type ) { |
|
| 330 | + $this->post_type_fields[ $type ][ $field['id'] ] = 1; |
|
| 331 | + |
|
| 332 | + if ( 'repeater' === $field['type'] ) { |
|
| 333 | + foreach ( $field['fields'] as $val ) { |
|
| 334 | + $this->post_type_fields[ $type ][ $val['id'] ] = 1; |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + if ( ! empty( $field['output'] ) ) { |
|
| 340 | + $this->output[ $field['id'] ] = isset( $this->output[ $field['id'] ] ) ? array_merge( $field['output'], $this->output[ $field['id'] ] ) : $field['output']; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + // Detect what field types are being used. |
|
| 344 | + if ( ! isset( $this->parent->fields[ $field['type'] ][ $field['id'] ] ) ) { |
|
| 345 | + $this->parent->fields[ $field['type'] ][ $field['id'] ] = 1; |
|
| 346 | + } else { |
|
| 347 | + $this->parent->fields[ $field['type'] ] = array( $field['id'] => 1 ); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + if ( isset( $this->options_defaults[ $field['id'] ] ) ) { |
|
| 351 | + $this->to_replace[ $field['id'] ] = $field; |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + if ( ! isset( $this->parent->options[ $field['id'] ] ) ) { |
|
| 356 | + $this->parent->sections[ ( count( $this->parent->sections ) - 1 ) ]['fields'][] = $field; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + if ( ! isset( $this->meta[ $this->post_id ][ $field['id'] ] ) ) { |
|
| 360 | + $this->meta[ $this->post_id ][ $field['id'] ] = $this->options_defaults[ $field['id'] ]; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + // Only override if it exists, and it's not the default. |
|
| 364 | + // phpcs:ignore Squiz.PHP.CommentedOutCode |
|
| 365 | + // if ( isset( $this->meta[ $this->post_id ][ $field['id'] ] ) && isset( $field['default'] ) && $this->meta[ $this->post_id ][ $field['id'] ] === $field['default'] ) { |
|
| 366 | + // unset($this->meta[$this->post_id][$field['id']]); |
|
| 367 | + // } . |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + if ( isset( $run_hooks ) && true === $run_hooks ) { |
|
| 376 | + $this->parent_options = array(); |
|
| 377 | + |
|
| 378 | + if ( ! empty( $this->to_replace ) ) { |
|
| 379 | + foreach ( $this->to_replace as $id => $field ) { |
|
| 380 | + |
|
| 381 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 382 | + add_filter( "redux/options/{$this->parent->args['opt_name']}/field/$id/register", array( $this, 'replace_field' ) ); |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + add_filter( "redux/options/{$this->parent->args['opt_name']}/options", array( $this, 'override_options' ) ); |
|
| 387 | + add_filter( "redux/field/{$this->parent->args['opt_name']}/_can_output_css", array( $this, 'override_can_output_css' ) ); |
|
| 388 | + add_filter( "redux/field/{$this->parent->args['opt_name']}/output_css", array( $this, 'output_css' ) ); |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Replace Field. |
|
| 394 | + * |
|
| 395 | + * @param array $field Field array. |
|
| 396 | + * |
|
| 397 | + * @return mixed |
|
| 398 | + */ |
|
| 399 | + public function replace_field( array $field ) { |
|
| 400 | + if ( isset( $this->to_replace[ $field['id'] ] ) ) { |
|
| 401 | + $field = $this->to_replace[ $field['id'] ]; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + return $field; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * Override CSS output. |
|
| 409 | + * |
|
| 410 | + * @param array $field Field array. |
|
| 411 | + * |
|
| 412 | + * @return array |
|
| 413 | + */ |
|
| 414 | + public function override_can_output_css( array $field ): array { |
|
| 415 | + if ( isset( $this->output[ $field['id'] ] ) ) { |
|
| 416 | + $field['force_output'] = true; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + return $field; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Output CSS. |
|
| 424 | + * |
|
| 425 | + * @param array $field Field array. |
|
| 426 | + * |
|
| 427 | + * @return array |
|
| 428 | + */ |
|
| 429 | + public function output_css( array $field ): array { |
|
| 430 | + if ( isset( $this->output[ $field['id'] ] ) ) { |
|
| 431 | + $field['output'] = $this->output[ $field['id'] ]; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + return $field; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Make sure the defaults are the defaults |
|
| 439 | + * |
|
| 440 | + * @param array $options Options array. |
|
| 441 | + * |
|
| 442 | + * @return array |
|
| 443 | + */ |
|
| 444 | + public function override_options( array $options ): array { |
|
| 445 | + $this->parent->default_values(); |
|
| 446 | + $this->parent_defaults = $this->parent->options_defaults; |
|
| 447 | + |
|
| 448 | + $meta = $this->get_meta( $this->post_id ); |
|
| 449 | + $data = wp_parse_args( $meta, $this->options_defaults ); |
|
| 450 | + |
|
| 451 | + foreach ( $data as $key => $value ) { |
|
| 452 | + if ( isset( $meta[ $key ] ) && '' !== $meta[ $key ] ) { |
|
| 453 | + $data[ $key ] = $meta[ $key ]; |
|
| 454 | + continue; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + if ( isset( $options[ $key ] ) ) { |
|
| 458 | + $data[ $key ] = $options[ $key ]; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + $this->parent->options_defaults = wp_parse_args( $this->options_defaults, $this->parent->options_defaults ); |
|
| 463 | + |
|
| 464 | + return wp_parse_args( $data, $options ); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Loop start. |
|
| 469 | + * |
|
| 470 | + * @param mixed $the_post WP_Post object. |
|
| 471 | + * |
|
| 472 | + * @return array|void |
|
| 473 | + */ |
|
| 474 | + public function loop_start( $the_post = array() ) { |
|
| 475 | + if ( is_admin() ) { |
|
| 476 | + return $the_post; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + if ( isset( $the_post ) && is_array( $the_post ) ) { |
|
| 480 | + global $post; |
|
| 481 | + $the_post = $post; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + if ( isset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ) ) { |
|
| 485 | + $GLOBALS[ $this->parent->args['global_variable'] ] = $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ]; |
|
| 486 | + unset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + // Override these values if they differ from the admin panel defaults. ;) . |
|
| 490 | + if ( in_array( $the_post->post_type, $this->post_types, true ) ) { |
|
| 491 | + $meta = $this->get_meta( $the_post->ID ); |
|
| 492 | + if ( empty( $meta ) ) { |
|
| 493 | + return; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + // Backup the args. |
|
| 497 | + $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] = $GLOBALS[ $this->parent->args['global_variable'] ]; |
|
| 498 | + $GLOBALS[ $this->parent->args['global_variable'] ] = wp_parse_args( $meta, $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ); |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Loop end. |
|
| 504 | + */ |
|
| 505 | + public function loop_end() { |
|
| 506 | + if ( isset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ) ) { |
|
| 507 | + $GLOBALS[ $this->parent->args['global_variable'] ] = $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ]; |
|
| 508 | + |
|
| 509 | + unset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ); |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * Enqueue fields. |
|
| 515 | + */ |
|
| 516 | + public function enqueue() { |
|
| 517 | + global $pagenow; |
|
| 518 | + |
|
| 519 | + $types = array(); |
|
| 520 | + |
|
| 521 | + // Enqueue CSS. |
|
| 522 | + foreach ( $this->boxes as $key => $box ) { |
|
| 523 | + if ( empty( $box['sections'] ) ) { |
|
| 524 | + continue; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + if ( isset( $box['post_types'] ) ) { |
|
| 528 | + $types = array_merge( $box['post_types'], $types ); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + if ( ! empty( $box['post_types'] ) ) { |
|
| 532 | + if ( ! is_array( $box['post_types'] ) ) { |
|
| 533 | + $box['post_types'] = array( $box['post_types'] ); |
|
| 534 | + $this->boxes[ $key ]['post_types'] = $box['post_types']; |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + if ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) { |
|
| 540 | + global $post; |
|
| 541 | + |
|
| 542 | + if ( in_array( $post->post_type, $types, true ) ) { |
|
| 543 | + $this->parent->transients = get_transient( $this->parent->args['opt_name'] . '-transients-metaboxes' ); |
|
| 544 | + $this->parent->transients_check = $this->parent->transients; |
|
| 545 | + |
|
| 546 | + if ( isset( $this->parent->transients['notices'] ) ) { |
|
| 547 | + $this->notices = $this->parent->transients['notices']; |
|
| 548 | + $this->parent->transients['last_save_mode'] = 'metaboxes'; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + delete_transient( $this->parent->args['opt_name'] . '-transients-metaboxes' ); |
|
| 552 | + $this->parent->enqueue_class->init(); |
|
| 553 | + |
|
| 554 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 555 | + do_action( "redux/metaboxes/{$this->parent->args['opt_name']}/enqueue" ); |
|
| 556 | + |
|
| 557 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 558 | + do_action( "redux/{$this->parent->args['opt_name']}/extensions/metaboxes/enqueue" ); |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * Redux metaboxes CSS |
|
| 562 | + * filter 'redux/page/{opt_name}/enqueue/redux-extension-metaboxes-css' |
|
| 563 | + */ |
|
| 564 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 565 | + wp_enqueue_style( |
|
| 566 | + 'redux-extension-metaboxes', |
|
| 567 | + apply_filters( "redux/metaboxes/{$this->parent->args['opt_name']}/enqueue/redux-extension-metaboxes-css", $this->extension_url . 'redux-extension-metaboxes.css' ), // phpcs:ignore: WordPress.NamingConventions.ValidHookName |
|
| 568 | + array(), |
|
| 569 | + self::$version |
|
| 570 | + ); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * Redux metaboxes JS |
|
| 575 | + * filter 'redux/page/{opt_name}/enqueue/redux-extension-metaboxes-js |
|
| 576 | + */ |
|
| 577 | + wp_enqueue_script( |
|
| 578 | + 'redux-extension-metaboxes', |
|
| 579 | + apply_filters( "redux/metaboxes/{$this->parent->args['opt_name']}/enqueue/redux-extension-metaboxes-js", $this->extension_url . 'redux-extension-metaboxes' . Redux_Functions::isMin() . '.js' ), // phpcs:ignore: WordPress.NamingConventions.ValidHookName |
|
| 580 | + array( 'jquery', 'redux-js' ), |
|
| 581 | + self::$version, |
|
| 582 | + true |
|
| 583 | + ); |
|
| 584 | + |
|
| 585 | + // Values used by the javascript. |
|
| 586 | + wp_localize_script( |
|
| 587 | + 'redux-extension-metaboxes', |
|
| 588 | + 'reduxMetaboxes', |
|
| 589 | + $this->wp_links |
|
| 590 | + ); |
|
| 591 | + |
|
| 592 | + wp_localize_script( |
|
| 593 | + 'redux-extension-metaboxes', |
|
| 594 | + 'reduxMetaboxesPageTemplate', |
|
| 595 | + array( |
|
| 596 | + '_wp_page_template' => get_post_meta( get_the_ID(), '_wp_page_template', true ), |
|
| 597 | + ) |
|
| 598 | + ); |
|
| 599 | + } |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + /* Post URLs to IDs function, supports custom post types - borrowed and modified from url_to_postid() in wp-includes/rewrite.php */ |
|
| 604 | + |
|
| 605 | + // Taken from http://betterwp.net/wordpress-tips/url_to_postid-for-custom-post-types/ |
|
| 606 | + // Customized to work with non-rewrite URLs |
|
| 607 | + // Modified by Dovy Paukstys (@dovy) of Redux Framework. |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * URL to PostID. |
|
| 611 | + * |
|
| 612 | + * @param string $url URL. |
|
| 613 | + * |
|
| 614 | + * @return int|mixed|void |
|
| 615 | + */ |
|
| 616 | + private function url_to_postid( string $url ) { |
|
| 617 | + global $wp_rewrite, $pagenow; |
|
| 618 | + |
|
| 619 | + if ( ! empty( $this->post_id ) ) { |
|
| 620 | + return $this->post_id; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + if ( isset( $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 624 | + $post = (int) sanitize_text_field( wp_unslash( $_GET['post'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 625 | + |
|
| 626 | + if ( ! empty( $post ) ) { |
|
| 627 | + return $post; |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + if ( 'post-new.php' === $pagenow || 'wp-login.php' === $pagenow ) { |
|
| 632 | + return; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + if ( is_admin() && 'post.php' === $pagenow && isset( $_POST['post_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 636 | + $post_id = sanitize_text_field( wp_unslash( $_POST['post_ID'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 637 | + |
|
| 638 | + if ( ! empty( $post_id ) && is_numeric( $post_id ) ) { |
|
| 639 | + return $post_id; |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + $post_id = url_to_postid( $url ); |
|
| 644 | + |
|
| 645 | + if ( isset( $post_id ) && '' !== (string) $post_id && 0 !== $post_id ) { |
|
| 646 | + return $post_id; |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + // First, check to see if there is a 'p=N' or 'page_id=N' to match against. |
|
| 650 | + if ( preg_match( '#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values ) ) { |
|
| 651 | + $id = absint( $values[2] ); |
|
| 652 | + if ( $id ) { |
|
| 653 | + return $id; |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + // Check to see if we are using rewrite rules. |
|
| 658 | + if ( isset( $wp_rewrite ) ) { |
|
| 659 | + $rewrite = $wp_rewrite->wp_rewrite_rules(); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options. |
|
| 663 | + if ( empty( $rewrite ) ) { |
|
| 664 | + if ( ! empty( $_GET ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 665 | + |
|
| 666 | + /************************************************************************ |
|
| 667 | 667 | * ADDED: Trys checks URL for ?posttype=postname |
| 668 | 668 | ************************************************************************ */ |
| 669 | 669 | |
| 670 | - // Assign $url to $temp_url just in case. :) . |
|
| 671 | - $temp_url = $url; |
|
| 672 | - |
|
| 673 | - // Get rid of the #anchor. |
|
| 674 | - $url_split = explode( '#', $temp_url ); |
|
| 675 | - $temp_url = $url_split[0]; |
|
| 676 | - |
|
| 677 | - // Get rid of URL ?query=string. |
|
| 678 | - $url_query = explode( '&', $temp_url ); |
|
| 679 | - $temp_url = $url_query[0]; |
|
| 680 | - |
|
| 681 | - // Get rid of ? mark. |
|
| 682 | - $url_query = explode( '?', $temp_url ); |
|
| 683 | - |
|
| 684 | - if ( ! empty( $url_query[1] ) && strpos( $url_query[1], '=' ) ) { |
|
| 685 | - $url_query = explode( '=', $url_query[1] ); |
|
| 686 | - |
|
| 687 | - if ( isset( $url_query[0] ) && isset( $url_query[1] ) ) { |
|
| 688 | - $args = array( |
|
| 689 | - 'name' => $url_query[1], |
|
| 690 | - 'post_type' => $url_query[0], |
|
| 691 | - 'showposts' => 1, |
|
| 692 | - ); |
|
| 693 | - |
|
| 694 | - if ( get_posts( $args ) === $post ) { |
|
| 695 | - return $post[0]->ID; |
|
| 696 | - } |
|
| 697 | - } |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - foreach ( $GLOBALS['wp_post_types'] as $key => $value ) { |
|
| 701 | - if ( ! empty( $_GET[ $key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 702 | - $args = array( |
|
| 703 | - 'name' => sanitize_text_field( wp_unslash( $_GET[ $key ] ) ), // phpcs:ignore WordPress.Security.NonceVerification |
|
| 704 | - 'post_type' => $key, |
|
| 705 | - 'showposts' => 1, |
|
| 706 | - ); |
|
| 707 | - |
|
| 708 | - if ( get_posts( $args ) === $post ) { |
|
| 709 | - return $post[0]->ID; |
|
| 710 | - } |
|
| 711 | - } |
|
| 712 | - } |
|
| 713 | - } |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - // Get rid of the #anchor. |
|
| 717 | - $url_split = explode( '#', $url ); |
|
| 718 | - $url = $url_split[0]; |
|
| 719 | - |
|
| 720 | - // Get rid of URL ?query=string. |
|
| 721 | - $url_query = explode( '?', $url ); |
|
| 722 | - $url = $url_query[0]; |
|
| 723 | - |
|
| 724 | - // Set the correct URL scheme. |
|
| 725 | - $scheme = wp_parse_url( home_url(), PHP_URL_SCHEME ); |
|
| 726 | - $url = set_url_scheme( $url, $scheme ); |
|
| 727 | - |
|
| 728 | - // Add 'www.' if it is absent and should be there. |
|
| 729 | - if ( false !== strpos( home_url(), '://www.' ) && false === strpos( $url, '://www.' ) ) { |
|
| 730 | - $url = str_replace( '://', '://www.', $url ); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - // Strip 'www.' if it is present and shouldn't be. |
|
| 734 | - if ( false === strpos( home_url(), '://www.' ) ) { |
|
| 735 | - $url = str_replace( '://www.', '://', $url ); |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - // Strip 'index.php/' if we're not using path info permalinks. |
|
| 739 | - if ( isset( $wp_rewrite ) && ! $wp_rewrite->using_index_permalinks() ) { |
|
| 740 | - $url = str_replace( 'index.php/', '', $url ); |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - if ( false !== strpos( $url, home_url() ) ) { |
|
| 744 | - // Chop off http://domain.com. |
|
| 745 | - $url = str_replace( home_url(), '', $url ); |
|
| 746 | - } else { |
|
| 747 | - // Chop off /path/to/blog. |
|
| 748 | - $home_path = wp_parse_url( home_url() ); |
|
| 749 | - $home_path = $home_path['path'] ?? ''; |
|
| 750 | - $url = str_replace( $home_path, '', $url ); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - // Trim leading and lagging slashes. |
|
| 754 | - $url = trim( $url, '/' ); |
|
| 755 | - |
|
| 756 | - $request = $url; |
|
| 757 | - |
|
| 758 | - if ( empty( $request ) && ( empty( $_GET ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 759 | - return get_option( 'page_on_front' ); |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - // Look for matches. |
|
| 763 | - $request_match = $request; |
|
| 764 | - |
|
| 765 | - foreach ( $rewrite as $match => $query ) { |
|
| 766 | - // If the requesting file is the anchor of the match, prepend it |
|
| 767 | - // to the path info. |
|
| 768 | - if ( ! empty( $url ) && ( $url !== $request ) && ( strpos( $match, $url ) === 0 ) ) { |
|
| 769 | - $request_match = $url . '/' . $request; |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - if ( preg_match( "!^$match!", $request_match, $matches ) ) { |
|
| 773 | - global $wp; |
|
| 774 | - |
|
| 775 | - // Got a match. |
|
| 776 | - // Trim the query of everything up to the '?'. |
|
| 777 | - $query = preg_replace( '!^.+\?!', '', $query ); |
|
| 778 | - |
|
| 779 | - // Substitute the substring matches into the query. |
|
| 780 | - $query = addslashes( WP_MatchesMapRegex::apply( $query, $matches ) ); |
|
| 781 | - |
|
| 782 | - // Filter out non-public query vars. |
|
| 783 | - parse_str( $query, $query_vars ); |
|
| 784 | - |
|
| 785 | - $query = array(); |
|
| 786 | - |
|
| 787 | - foreach ( $query_vars as $key => $value ) { |
|
| 788 | - if ( in_array( $key, $wp->public_query_vars, true ) ) { |
|
| 789 | - $query[ $key ] = $value; |
|
| 790 | - } |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - /************************************************************************ |
|
| 670 | + // Assign $url to $temp_url just in case. :) . |
|
| 671 | + $temp_url = $url; |
|
| 672 | + |
|
| 673 | + // Get rid of the #anchor. |
|
| 674 | + $url_split = explode( '#', $temp_url ); |
|
| 675 | + $temp_url = $url_split[0]; |
|
| 676 | + |
|
| 677 | + // Get rid of URL ?query=string. |
|
| 678 | + $url_query = explode( '&', $temp_url ); |
|
| 679 | + $temp_url = $url_query[0]; |
|
| 680 | + |
|
| 681 | + // Get rid of ? mark. |
|
| 682 | + $url_query = explode( '?', $temp_url ); |
|
| 683 | + |
|
| 684 | + if ( ! empty( $url_query[1] ) && strpos( $url_query[1], '=' ) ) { |
|
| 685 | + $url_query = explode( '=', $url_query[1] ); |
|
| 686 | + |
|
| 687 | + if ( isset( $url_query[0] ) && isset( $url_query[1] ) ) { |
|
| 688 | + $args = array( |
|
| 689 | + 'name' => $url_query[1], |
|
| 690 | + 'post_type' => $url_query[0], |
|
| 691 | + 'showposts' => 1, |
|
| 692 | + ); |
|
| 693 | + |
|
| 694 | + if ( get_posts( $args ) === $post ) { |
|
| 695 | + return $post[0]->ID; |
|
| 696 | + } |
|
| 697 | + } |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + foreach ( $GLOBALS['wp_post_types'] as $key => $value ) { |
|
| 701 | + if ( ! empty( $_GET[ $key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 702 | + $args = array( |
|
| 703 | + 'name' => sanitize_text_field( wp_unslash( $_GET[ $key ] ) ), // phpcs:ignore WordPress.Security.NonceVerification |
|
| 704 | + 'post_type' => $key, |
|
| 705 | + 'showposts' => 1, |
|
| 706 | + ); |
|
| 707 | + |
|
| 708 | + if ( get_posts( $args ) === $post ) { |
|
| 709 | + return $post[0]->ID; |
|
| 710 | + } |
|
| 711 | + } |
|
| 712 | + } |
|
| 713 | + } |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + // Get rid of the #anchor. |
|
| 717 | + $url_split = explode( '#', $url ); |
|
| 718 | + $url = $url_split[0]; |
|
| 719 | + |
|
| 720 | + // Get rid of URL ?query=string. |
|
| 721 | + $url_query = explode( '?', $url ); |
|
| 722 | + $url = $url_query[0]; |
|
| 723 | + |
|
| 724 | + // Set the correct URL scheme. |
|
| 725 | + $scheme = wp_parse_url( home_url(), PHP_URL_SCHEME ); |
|
| 726 | + $url = set_url_scheme( $url, $scheme ); |
|
| 727 | + |
|
| 728 | + // Add 'www.' if it is absent and should be there. |
|
| 729 | + if ( false !== strpos( home_url(), '://www.' ) && false === strpos( $url, '://www.' ) ) { |
|
| 730 | + $url = str_replace( '://', '://www.', $url ); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + // Strip 'www.' if it is present and shouldn't be. |
|
| 734 | + if ( false === strpos( home_url(), '://www.' ) ) { |
|
| 735 | + $url = str_replace( '://www.', '://', $url ); |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + // Strip 'index.php/' if we're not using path info permalinks. |
|
| 739 | + if ( isset( $wp_rewrite ) && ! $wp_rewrite->using_index_permalinks() ) { |
|
| 740 | + $url = str_replace( 'index.php/', '', $url ); |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + if ( false !== strpos( $url, home_url() ) ) { |
|
| 744 | + // Chop off http://domain.com. |
|
| 745 | + $url = str_replace( home_url(), '', $url ); |
|
| 746 | + } else { |
|
| 747 | + // Chop off /path/to/blog. |
|
| 748 | + $home_path = wp_parse_url( home_url() ); |
|
| 749 | + $home_path = $home_path['path'] ?? ''; |
|
| 750 | + $url = str_replace( $home_path, '', $url ); |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + // Trim leading and lagging slashes. |
|
| 754 | + $url = trim( $url, '/' ); |
|
| 755 | + |
|
| 756 | + $request = $url; |
|
| 757 | + |
|
| 758 | + if ( empty( $request ) && ( empty( $_GET ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 759 | + return get_option( 'page_on_front' ); |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + // Look for matches. |
|
| 763 | + $request_match = $request; |
|
| 764 | + |
|
| 765 | + foreach ( $rewrite as $match => $query ) { |
|
| 766 | + // If the requesting file is the anchor of the match, prepend it |
|
| 767 | + // to the path info. |
|
| 768 | + if ( ! empty( $url ) && ( $url !== $request ) && ( strpos( $match, $url ) === 0 ) ) { |
|
| 769 | + $request_match = $url . '/' . $request; |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + if ( preg_match( "!^$match!", $request_match, $matches ) ) { |
|
| 773 | + global $wp; |
|
| 774 | + |
|
| 775 | + // Got a match. |
|
| 776 | + // Trim the query of everything up to the '?'. |
|
| 777 | + $query = preg_replace( '!^.+\?!', '', $query ); |
|
| 778 | + |
|
| 779 | + // Substitute the substring matches into the query. |
|
| 780 | + $query = addslashes( WP_MatchesMapRegex::apply( $query, $matches ) ); |
|
| 781 | + |
|
| 782 | + // Filter out non-public query vars. |
|
| 783 | + parse_str( $query, $query_vars ); |
|
| 784 | + |
|
| 785 | + $query = array(); |
|
| 786 | + |
|
| 787 | + foreach ( $query_vars as $key => $value ) { |
|
| 788 | + if ( in_array( $key, $wp->public_query_vars, true ) ) { |
|
| 789 | + $query[ $key ] = $value; |
|
| 790 | + } |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + /************************************************************************ |
|
| 794 | 794 | * ADDED: $GLOBALS['wp_post_types'] doesn't seem to have custom posttypes |
| 795 | 795 | * Trying below to find posttypes in $rewrite rules |
| 796 | 796 | ************************************************************************ */ |
| 797 | 797 | |
| 798 | - // PostType Array. |
|
| 799 | - $post_types = array(); |
|
| 800 | - |
|
| 801 | - foreach ( $rewrite as $value ) { |
|
| 802 | - if ( preg_match( '/post_type=([^&]+)/i', $value, $matched ) ) { |
|
| 803 | - if ( isset( $matched[1] ) && ! in_array( $matched[1], $post_types, true ) ) { |
|
| 804 | - $post_types[] = $matched[1]; |
|
| 805 | - } |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - foreach ( $query_vars as $key => $value ) { |
|
| 810 | - if ( in_array( $key, $post_types, true ) ) { |
|
| 811 | - $query['post_type'] = $key; |
|
| 812 | - $query['postname'] = $value; |
|
| 813 | - } |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - /************************************************************************ |
|
| 798 | + // PostType Array. |
|
| 799 | + $post_types = array(); |
|
| 800 | + |
|
| 801 | + foreach ( $rewrite as $value ) { |
|
| 802 | + if ( preg_match( '/post_type=([^&]+)/i', $value, $matched ) ) { |
|
| 803 | + if ( isset( $matched[1] ) && ! in_array( $matched[1], $post_types, true ) ) { |
|
| 804 | + $post_types[] = $matched[1]; |
|
| 805 | + } |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + foreach ( $query_vars as $key => $value ) { |
|
| 810 | + if ( in_array( $key, $post_types, true ) ) { |
|
| 811 | + $query['post_type'] = $key; |
|
| 812 | + $query['postname'] = $value; |
|
| 813 | + } |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + /************************************************************************ |
|
| 817 | 817 | * END ADD |
| 818 | 818 | ************************************************************************ */ |
| 819 | 819 | |
| 820 | - // Taken from class-wp.php. |
|
| 821 | - foreach ( $GLOBALS['wp_post_types'] as $post_type => $t ) { |
|
| 822 | - if ( isset( $t->query_var ) ) { |
|
| 823 | - $post_type_query_vars[ $t->query_var ] = $post_type; |
|
| 824 | - } |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - foreach ( $wp->public_query_vars as $wpvar ) { |
|
| 828 | - if ( isset( $wp->extra_query_vars[ $wpvar ] ) ) { |
|
| 829 | - $query[ $wpvar ] = $wp->extra_query_vars[ $wpvar ]; |
|
| 830 | - } elseif ( isset( $_POST[ $wpvar ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 831 | - $query[ $wpvar ] = sanitize_text_field( wp_unslash( $_POST[ $wpvar ] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 832 | - } elseif ( isset( $_GET[ $wpvar ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 833 | - $query[ $wpvar ] = sanitize_text_field( wp_unslash( $_GET[ $wpvar ] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 834 | - } elseif ( isset( $query_vars[ $wpvar ] ) ) { |
|
| 835 | - $query[ $wpvar ] = $query_vars[ $wpvar ]; |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - if ( ! empty( $query[ $wpvar ] ) ) { |
|
| 839 | - if ( ! is_array( $query[ $wpvar ] ) ) { |
|
| 840 | - $query[ $wpvar ] = (string) $query[ $wpvar ]; |
|
| 841 | - } else { |
|
| 842 | - foreach ( $query[ $wpvar ] as $vkey => $v ) { |
|
| 843 | - if ( ! is_object( $v ) ) { |
|
| 844 | - $query[ $wpvar ][ $vkey ] = (string) $v; |
|
| 845 | - } |
|
| 846 | - } |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - if ( isset( $post_type_query_vars[ $wpvar ] ) ) { |
|
| 850 | - $query['post_type'] = $post_type_query_vars[ $wpvar ]; |
|
| 851 | - $query['name'] = $query[ $wpvar ]; |
|
| 852 | - } |
|
| 853 | - } |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - // Do the query. |
|
| 857 | - if ( ! empty( $query['pagename'] ) ) { |
|
| 858 | - $args = array( |
|
| 859 | - 'name' => $query['pagename'], |
|
| 860 | - 'post_type' => 'page', |
|
| 861 | - 'showposts' => 1, |
|
| 862 | - ); |
|
| 863 | - |
|
| 864 | - if ( isset( $post ) && get_posts( $args ) === $post ) { |
|
| 865 | - return $post[0]->ID; |
|
| 866 | - } |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - $query = new WP_Query( $query ); |
|
| 870 | - |
|
| 871 | - if ( ! empty( $query->posts ) && $query->is_singular ) { |
|
| 872 | - return $query->post->ID; |
|
| 873 | - } else { |
|
| 874 | - |
|
| 875 | - // WooCommerce override. |
|
| 876 | - if ( isset( $query->query['post_type'] ) && 'product' === $query->query['post_type'] && class_exists( 'WooCommerce' ) ) { |
|
| 877 | - return get_option( 'woocommerce_shop_page_id' ); |
|
| 878 | - } |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - if ( ( empty( $query->page ) ) && ( empty( $query->pagename ) ) ) { |
|
| 882 | - return 0; |
|
| 883 | - } |
|
| 884 | - } |
|
| 885 | - } |
|
| 886 | - |
|
| 887 | - return 0; |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - /** |
|
| 891 | - * Get default values. |
|
| 892 | - */ |
|
| 893 | - public function default_values() { |
|
| 894 | - if ( ! empty( $this->boxes ) && empty( $this->options_defaults ) ) { |
|
| 895 | - foreach ( $this->boxes as $key => $box ) { |
|
| 896 | - if ( empty( $box['sections'] ) ) { |
|
| 897 | - continue; |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - // fill the cache. |
|
| 901 | - foreach ( $box['sections'] as $sk => $section ) { |
|
| 902 | - if ( ! isset( $section['id'] ) ) { |
|
| 903 | - if ( ! is_numeric( $sk ) || ! isset( $section['title'] ) ) { |
|
| 904 | - $section['id'] = $sk; |
|
| 905 | - } else { |
|
| 906 | - $section['id'] = sanitize_text_field( $section['title'] ); |
|
| 907 | - } |
|
| 908 | - $this->boxes[ $key ]['sections'][ $sk ] = $section; |
|
| 909 | - } |
|
| 910 | - if ( isset( $section['fields'] ) ) { |
|
| 911 | - foreach ( $section['fields'] as $k => $field ) { |
|
| 912 | - |
|
| 913 | - if ( empty( $field['id'] ) && empty( $field['type'] ) ) { |
|
| 914 | - continue; |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - if ( 'ace_editor' === $field['type'] && isset( $field['options'] ) ) { |
|
| 918 | - $this->boxes[ $key ]['sections'][ $sk ]['fields'][ $k ]['args'] = $field['options']; |
|
| 919 | - unset( $this->boxes[ $key ]['sections'][ $sk ]['fields'][ $k ]['options'] ); |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - if ( 'section' === $field['type'] && isset( $field['indent'] ) && ( true === $field['indent'] || 'true' === $field['indent'] ) ) { |
|
| 923 | - $field['class'] = $field['class'] ?? ''; |
|
| 924 | - $field['class'] .= 'redux-section-indent-start'; |
|
| 925 | - |
|
| 926 | - $this->boxes[ $key ]['sections'][ $sk ]['fields'][ $k ] = $field; |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - if ( ! isset( $this->parent->options_defaults_class ) ) { |
|
| 930 | - $this->parent->options_defaults_class = new Redux_Options_Defaults(); |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - $this->parent->options_defaults_class->field_default_values( $this->parent->args['opt_name'], $field ); |
|
| 934 | - |
|
| 935 | - if ( 'repeater' === $field['type'] ) { |
|
| 936 | - foreach ( $field['fields'] as $f ) { |
|
| 937 | - $this->parent->options_defaults_class->field_default_values( $this->parent->args['opt_name'], $f, null, true ); |
|
| 938 | - } |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - $this->parent->options_defaults = $this->parent->options_defaults_class->options_defaults; |
|
| 942 | - } |
|
| 943 | - } |
|
| 944 | - } |
|
| 945 | - } |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - if ( empty( $this->meta[ $this->post_id ] ) ) { |
|
| 949 | - $this->meta[ $this->post_id ] = $this->get_meta( $this->post_id ); |
|
| 950 | - } |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * Add Meta Boxes |
|
| 955 | - */ |
|
| 956 | - public function add() { |
|
| 957 | - if ( empty( $this->boxes ) || ! is_array( $this->boxes ) ) { |
|
| 958 | - return; |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - foreach ( $this->boxes as $key => $box ) { |
|
| 962 | - if ( empty( $box['sections'] ) ) { |
|
| 963 | - continue; |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - // Save users from themselves. |
|
| 967 | - if ( isset( $box['position'] ) && ! in_array( strtolower( $box['position'] ), array( 'normal', 'advanced', 'side' ), true ) ) { |
|
| 968 | - unset( $box['position'] ); |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - if ( isset( $box['priority'] ) && ! in_array( strtolower( $box['priority'] ), array( 'high', 'core', 'default', 'low' ), true ) ) { |
|
| 972 | - unset( $box['priority'] ); |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - $defaults = array( |
|
| 976 | - 'id' => $key . '-' . $this->parent->args['opt_name'], |
|
| 977 | - 'post_types' => array( 'page', 'post' ), |
|
| 978 | - 'position' => 'normal', |
|
| 979 | - 'priority' => 'high', |
|
| 980 | - ); |
|
| 981 | - |
|
| 982 | - $box = wp_parse_args( $box, $defaults ); |
|
| 983 | - if ( ! empty( $box['post_types'] ) ) { |
|
| 984 | - foreach ( $box['post_types'] as $posttype ) { |
|
| 985 | - if ( isset( $box['title'] ) ) { |
|
| 986 | - $title = $box['title']; |
|
| 987 | - } elseif ( isset( $box['sections'] ) && 1 === count( $box['sections'] ) && isset( $box['sections'][0]['fields'] ) && 1 === count( $box['sections'][0]['fields'] ) && isset( $box['sections'][0]['fields'][0]['title'] ) ) { |
|
| 988 | - |
|
| 989 | - // If only one field in this box. |
|
| 990 | - $title = $box['sections'][0]['fields'][0]['title']; |
|
| 991 | - } else { |
|
| 992 | - $title = ucfirst( $posttype ) . ' ' . __( 'Options', 'redux-framework' ); |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - $args = array( |
|
| 996 | - 'position' => $box['position'], |
|
| 997 | - 'sections' => $box['sections'], |
|
| 998 | - 'key' => $key, |
|
| 999 | - ); |
|
| 1000 | - |
|
| 1001 | - // Override the parent args on a metabox level. |
|
| 1002 | - if ( empty( $this->orig_args ) ) { |
|
| 1003 | - $this->orig_args = $this->parent->args; |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - if ( isset( $box['args'] ) ) { |
|
| 1007 | - $this->parent->args = wp_parse_args( $box['args'], $this->orig_args ); |
|
| 1008 | - } elseif ( $this->parent->args !== $this->orig_args ) { |
|
| 1009 | - $this->parent->args = $this->orig_args; |
|
| 1010 | - } |
|
| 1011 | - |
|
| 1012 | - add_filter( 'postbox_classes_' . $posttype . '_redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id'], array( $this, 'add_box_classes' ) ); |
|
| 1013 | - |
|
| 1014 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1015 | - do_action( 'redux/' . $this->parent->args['opt_name'] . '/extensions/metabox/add', $this, $box, $posttype ); |
|
| 1016 | - |
|
| 1017 | - if ( isset( $box['post_format'] ) ) { |
|
| 1018 | - add_filter( 'postbox_classes_' . $posttype . '_redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id'], array( $this, 'add_box_hide_class' ) ); |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - // phpcs:ignore Generic.Strings.UnnecessaryStringConcat |
|
| 1022 | - call_user_func( 'add' . '_meta' . '_box', 'redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id'], $title, array( $this, 'generate_boxes' ), $posttype, $box['position'], $box['priority'], $args ); |
|
| 1023 | - } |
|
| 1024 | - } |
|
| 1025 | - } |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - /** |
|
| 1029 | - * Add hidden class to metabox DIV. |
|
| 1030 | - * |
|
| 1031 | - * @param array $classes Class array. |
|
| 1032 | - * |
|
| 1033 | - * @return array |
|
| 1034 | - */ |
|
| 1035 | - public function add_box_hide_class( array $classes ): array { |
|
| 1036 | - $classes[] = 'hide'; |
|
| 1037 | - |
|
| 1038 | - return $classes; |
|
| 1039 | - } |
|
| 1040 | - |
|
| 1041 | - /** |
|
| 1042 | - * Field Defaults. |
|
| 1043 | - * |
|
| 1044 | - * @param mixed $field_id ID. |
|
| 1045 | - * |
|
| 1046 | - * @return mixed|string |
|
| 1047 | - */ |
|
| 1048 | - private function field_default( $field_id ) { |
|
| 1049 | - if ( ! isset( $this->parent->options_defaults ) ) { |
|
| 1050 | - $this->parent->options_defaults = $this->parent->default_values(); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - if ( ! isset( $this->parent->options ) || empty( $this->parent->options ) ) { |
|
| 1054 | - if ( ! isset( $this->parent->options_class ) ) { |
|
| 1055 | - $this->parent->options_class = new Redux_Options_Constructor( $this->parent ); |
|
| 1056 | - } |
|
| 1057 | - |
|
| 1058 | - $this->parent->options_class->get(); |
|
| 1059 | - } |
|
| 1060 | - |
|
| 1061 | - $this->options = $this->parent->options; |
|
| 1062 | - |
|
| 1063 | - if ( isset( $this->parent->options[ $field_id['id'] ] ) && isset( $this->parent->options_defaults[ $field_id['id'] ] ) && $this->parent->options[ $field_id['id'] ] !== $this->parent->options_defaults[ $field_id['id'] ] ) { |
|
| 1064 | - return $this->parent->options[ $field_id['id'] ]; |
|
| 1065 | - } else { |
|
| 1066 | - if ( empty( $this->options_defaults ) ) { |
|
| 1067 | - $this->default_values(); // fill cache. |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - $data = ''; |
|
| 1071 | - if ( ! empty( $this->options_defaults ) ) { |
|
| 1072 | - $data = $this->options_defaults[ $field_id['id'] ] ?? ''; |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - if ( empty( $data ) && isset( $this->parent->options_defaults[ $field_id['id'] ] ) ) { |
|
| 1076 | - $data = $this->parent->options_defaults[ $field_id['id'] ] ?? ''; |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - return $data; |
|
| 1080 | - } |
|
| 1081 | - } |
|
| 1082 | - |
|
| 1083 | - /** |
|
| 1084 | - * Function to get and cache the post meta. |
|
| 1085 | - * |
|
| 1086 | - * @param mixed $id ID. |
|
| 1087 | - * |
|
| 1088 | - * @return array |
|
| 1089 | - */ |
|
| 1090 | - private function get_meta( $id ): array { |
|
| 1091 | - if ( ! isset( $this->meta[ $id ] ) ) { |
|
| 1092 | - $this->meta[ $id ] = array(); |
|
| 1093 | - $o_data = get_post_meta( $id ); |
|
| 1094 | - |
|
| 1095 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1096 | - $o_data = apply_filters( "redux/metaboxes/{$this->parent->args['opt_name']}/get_meta", $o_data ); |
|
| 1097 | - |
|
| 1098 | - if ( ! empty( $o_data ) ) { |
|
| 1099 | - foreach ( $o_data as $key => $value ) { |
|
| 1100 | - if ( 1 === count( $value ) ) { |
|
| 1101 | - $this->meta[ $id ][ $key ] = maybe_unserialize( $value[0] ); |
|
| 1102 | - } else { |
|
| 1103 | - $new_value = array_map( 'maybe_unserialize', $value ); |
|
| 1104 | - |
|
| 1105 | - $this->meta[ $id ][ $key ] = $new_value[0]; |
|
| 1106 | - } |
|
| 1107 | - } |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - if ( isset( $this->meta[ $id ][ $this->parent->args['opt_name'] ] ) ) { |
|
| 1111 | - $data = maybe_unserialize( $this->meta[ $id ][ $this->parent->args['opt_name'] ] ); |
|
| 1112 | - |
|
| 1113 | - foreach ( $data as $key => $value ) { |
|
| 1114 | - $this->meta[ $id ][ $key ] = $value; |
|
| 1115 | - update_post_meta( $id, $key, $value ); |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - unset( $this->meta[ $id ][ $this->parent->args['opt_name'] ] ); |
|
| 1119 | - |
|
| 1120 | - delete_post_meta( $id, $this->parent->args['opt_name'] ); |
|
| 1121 | - } |
|
| 1122 | - } |
|
| 1123 | - |
|
| 1124 | - return $this->meta[ $id ]; |
|
| 1125 | - } |
|
| 1126 | - |
|
| 1127 | - /** |
|
| 1128 | - * Get values. |
|
| 1129 | - * |
|
| 1130 | - * @param mixed $the_post Post object/id. |
|
| 1131 | - * @param string $meta_key Meta key. |
|
| 1132 | - * @param mixed $def_val Def value. |
|
| 1133 | - * |
|
| 1134 | - * @return array|mixed|string |
|
| 1135 | - */ |
|
| 1136 | - public function get_values( $the_post, string $meta_key = '', $def_val = '' ) { |
|
| 1137 | - |
|
| 1138 | - // Override these values if they differ from the admin panel defaults. ;) . |
|
| 1139 | - if ( isset( $the_post->post_type ) && in_array( $the_post->post_type, $this->post_types, true ) ) { |
|
| 1140 | - if ( isset( $this->post_type_values[ $the_post->post_type ] ) ) { |
|
| 1141 | - $meta = $this->post_type_fields[ $the_post->post_type ]; |
|
| 1142 | - } else { |
|
| 1143 | - $defaults = array(); |
|
| 1144 | - if ( ! empty( $this->post_type_fields[ $the_post->post_type ] ) ) { |
|
| 1145 | - foreach ( $this->post_type_fields[ $the_post->post_type ] as $key => $null ) { |
|
| 1146 | - if ( isset( $this->options_defaults[ $key ] ) ) { |
|
| 1147 | - $defaults[ $key ] = $this->options_defaults[ $key ]; |
|
| 1148 | - } |
|
| 1149 | - } |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - $meta = wp_parse_args( $this->get_meta( $the_post->ID ), $defaults ); |
|
| 1153 | - |
|
| 1154 | - $this->post_type_fields[ $the_post->post_type ] = $meta; |
|
| 1155 | - } |
|
| 1156 | - |
|
| 1157 | - if ( ! empty( $meta_key ) ) { |
|
| 1158 | - if ( ! isset( $meta[ $meta_key ] ) ) { |
|
| 1159 | - $meta[ $meta_key ] = $def_val; |
|
| 1160 | - } |
|
| 1161 | - |
|
| 1162 | - return $meta[ $meta_key ]; |
|
| 1163 | - } else { |
|
| 1164 | - return $meta; |
|
| 1165 | - } |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - return $def_val; |
|
| 1169 | - } |
|
| 1170 | - |
|
| 1171 | - /** |
|
| 1172 | - * Generate Boxes. |
|
| 1173 | - * |
|
| 1174 | - * @param mixed $post Post. |
|
| 1175 | - * @param array $metabox Metabox array. |
|
| 1176 | - */ |
|
| 1177 | - public function generate_boxes( $post, array $metabox ) { |
|
| 1178 | - if ( ! empty( $metabox['args']['permissions'] ) && ! Redux_Helpers::current_user_can( $metabox['args']['permissions'] ) ) { |
|
| 1179 | - return; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - $sections = $metabox['args']['sections']; |
|
| 1183 | - |
|
| 1184 | - wp_nonce_field( 'redux_metaboxes_meta_nonce', 'redux_metaboxes_meta_nonce' ); |
|
| 1185 | - |
|
| 1186 | - wp_dequeue_script( 'json-view-js' ); |
|
| 1187 | - |
|
| 1188 | - $sidebar = true; |
|
| 1189 | - |
|
| 1190 | - if ( 'side' === $metabox['args']['position'] || 1 === count( $sections ) || ( isset( $metabox['args']['sidebar'] ) && false === $metabox['args']['sidebar'] ) ) { |
|
| 1191 | - $sidebar = false; // Show the section dividers or not. |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - ?> |
|
| 820 | + // Taken from class-wp.php. |
|
| 821 | + foreach ( $GLOBALS['wp_post_types'] as $post_type => $t ) { |
|
| 822 | + if ( isset( $t->query_var ) ) { |
|
| 823 | + $post_type_query_vars[ $t->query_var ] = $post_type; |
|
| 824 | + } |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + foreach ( $wp->public_query_vars as $wpvar ) { |
|
| 828 | + if ( isset( $wp->extra_query_vars[ $wpvar ] ) ) { |
|
| 829 | + $query[ $wpvar ] = $wp->extra_query_vars[ $wpvar ]; |
|
| 830 | + } elseif ( isset( $_POST[ $wpvar ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 831 | + $query[ $wpvar ] = sanitize_text_field( wp_unslash( $_POST[ $wpvar ] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 832 | + } elseif ( isset( $_GET[ $wpvar ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 833 | + $query[ $wpvar ] = sanitize_text_field( wp_unslash( $_GET[ $wpvar ] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 834 | + } elseif ( isset( $query_vars[ $wpvar ] ) ) { |
|
| 835 | + $query[ $wpvar ] = $query_vars[ $wpvar ]; |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + if ( ! empty( $query[ $wpvar ] ) ) { |
|
| 839 | + if ( ! is_array( $query[ $wpvar ] ) ) { |
|
| 840 | + $query[ $wpvar ] = (string) $query[ $wpvar ]; |
|
| 841 | + } else { |
|
| 842 | + foreach ( $query[ $wpvar ] as $vkey => $v ) { |
|
| 843 | + if ( ! is_object( $v ) ) { |
|
| 844 | + $query[ $wpvar ][ $vkey ] = (string) $v; |
|
| 845 | + } |
|
| 846 | + } |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + if ( isset( $post_type_query_vars[ $wpvar ] ) ) { |
|
| 850 | + $query['post_type'] = $post_type_query_vars[ $wpvar ]; |
|
| 851 | + $query['name'] = $query[ $wpvar ]; |
|
| 852 | + } |
|
| 853 | + } |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + // Do the query. |
|
| 857 | + if ( ! empty( $query['pagename'] ) ) { |
|
| 858 | + $args = array( |
|
| 859 | + 'name' => $query['pagename'], |
|
| 860 | + 'post_type' => 'page', |
|
| 861 | + 'showposts' => 1, |
|
| 862 | + ); |
|
| 863 | + |
|
| 864 | + if ( isset( $post ) && get_posts( $args ) === $post ) { |
|
| 865 | + return $post[0]->ID; |
|
| 866 | + } |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + $query = new WP_Query( $query ); |
|
| 870 | + |
|
| 871 | + if ( ! empty( $query->posts ) && $query->is_singular ) { |
|
| 872 | + return $query->post->ID; |
|
| 873 | + } else { |
|
| 874 | + |
|
| 875 | + // WooCommerce override. |
|
| 876 | + if ( isset( $query->query['post_type'] ) && 'product' === $query->query['post_type'] && class_exists( 'WooCommerce' ) ) { |
|
| 877 | + return get_option( 'woocommerce_shop_page_id' ); |
|
| 878 | + } |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + if ( ( empty( $query->page ) ) && ( empty( $query->pagename ) ) ) { |
|
| 882 | + return 0; |
|
| 883 | + } |
|
| 884 | + } |
|
| 885 | + } |
|
| 886 | + |
|
| 887 | + return 0; |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + /** |
|
| 891 | + * Get default values. |
|
| 892 | + */ |
|
| 893 | + public function default_values() { |
|
| 894 | + if ( ! empty( $this->boxes ) && empty( $this->options_defaults ) ) { |
|
| 895 | + foreach ( $this->boxes as $key => $box ) { |
|
| 896 | + if ( empty( $box['sections'] ) ) { |
|
| 897 | + continue; |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + // fill the cache. |
|
| 901 | + foreach ( $box['sections'] as $sk => $section ) { |
|
| 902 | + if ( ! isset( $section['id'] ) ) { |
|
| 903 | + if ( ! is_numeric( $sk ) || ! isset( $section['title'] ) ) { |
|
| 904 | + $section['id'] = $sk; |
|
| 905 | + } else { |
|
| 906 | + $section['id'] = sanitize_text_field( $section['title'] ); |
|
| 907 | + } |
|
| 908 | + $this->boxes[ $key ]['sections'][ $sk ] = $section; |
|
| 909 | + } |
|
| 910 | + if ( isset( $section['fields'] ) ) { |
|
| 911 | + foreach ( $section['fields'] as $k => $field ) { |
|
| 912 | + |
|
| 913 | + if ( empty( $field['id'] ) && empty( $field['type'] ) ) { |
|
| 914 | + continue; |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + if ( 'ace_editor' === $field['type'] && isset( $field['options'] ) ) { |
|
| 918 | + $this->boxes[ $key ]['sections'][ $sk ]['fields'][ $k ]['args'] = $field['options']; |
|
| 919 | + unset( $this->boxes[ $key ]['sections'][ $sk ]['fields'][ $k ]['options'] ); |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + if ( 'section' === $field['type'] && isset( $field['indent'] ) && ( true === $field['indent'] || 'true' === $field['indent'] ) ) { |
|
| 923 | + $field['class'] = $field['class'] ?? ''; |
|
| 924 | + $field['class'] .= 'redux-section-indent-start'; |
|
| 925 | + |
|
| 926 | + $this->boxes[ $key ]['sections'][ $sk ]['fields'][ $k ] = $field; |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + if ( ! isset( $this->parent->options_defaults_class ) ) { |
|
| 930 | + $this->parent->options_defaults_class = new Redux_Options_Defaults(); |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + $this->parent->options_defaults_class->field_default_values( $this->parent->args['opt_name'], $field ); |
|
| 934 | + |
|
| 935 | + if ( 'repeater' === $field['type'] ) { |
|
| 936 | + foreach ( $field['fields'] as $f ) { |
|
| 937 | + $this->parent->options_defaults_class->field_default_values( $this->parent->args['opt_name'], $f, null, true ); |
|
| 938 | + } |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + $this->parent->options_defaults = $this->parent->options_defaults_class->options_defaults; |
|
| 942 | + } |
|
| 943 | + } |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + if ( empty( $this->meta[ $this->post_id ] ) ) { |
|
| 949 | + $this->meta[ $this->post_id ] = $this->get_meta( $this->post_id ); |
|
| 950 | + } |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * Add Meta Boxes |
|
| 955 | + */ |
|
| 956 | + public function add() { |
|
| 957 | + if ( empty( $this->boxes ) || ! is_array( $this->boxes ) ) { |
|
| 958 | + return; |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + foreach ( $this->boxes as $key => $box ) { |
|
| 962 | + if ( empty( $box['sections'] ) ) { |
|
| 963 | + continue; |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + // Save users from themselves. |
|
| 967 | + if ( isset( $box['position'] ) && ! in_array( strtolower( $box['position'] ), array( 'normal', 'advanced', 'side' ), true ) ) { |
|
| 968 | + unset( $box['position'] ); |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + if ( isset( $box['priority'] ) && ! in_array( strtolower( $box['priority'] ), array( 'high', 'core', 'default', 'low' ), true ) ) { |
|
| 972 | + unset( $box['priority'] ); |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + $defaults = array( |
|
| 976 | + 'id' => $key . '-' . $this->parent->args['opt_name'], |
|
| 977 | + 'post_types' => array( 'page', 'post' ), |
|
| 978 | + 'position' => 'normal', |
|
| 979 | + 'priority' => 'high', |
|
| 980 | + ); |
|
| 981 | + |
|
| 982 | + $box = wp_parse_args( $box, $defaults ); |
|
| 983 | + if ( ! empty( $box['post_types'] ) ) { |
|
| 984 | + foreach ( $box['post_types'] as $posttype ) { |
|
| 985 | + if ( isset( $box['title'] ) ) { |
|
| 986 | + $title = $box['title']; |
|
| 987 | + } elseif ( isset( $box['sections'] ) && 1 === count( $box['sections'] ) && isset( $box['sections'][0]['fields'] ) && 1 === count( $box['sections'][0]['fields'] ) && isset( $box['sections'][0]['fields'][0]['title'] ) ) { |
|
| 988 | + |
|
| 989 | + // If only one field in this box. |
|
| 990 | + $title = $box['sections'][0]['fields'][0]['title']; |
|
| 991 | + } else { |
|
| 992 | + $title = ucfirst( $posttype ) . ' ' . __( 'Options', 'redux-framework' ); |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + $args = array( |
|
| 996 | + 'position' => $box['position'], |
|
| 997 | + 'sections' => $box['sections'], |
|
| 998 | + 'key' => $key, |
|
| 999 | + ); |
|
| 1000 | + |
|
| 1001 | + // Override the parent args on a metabox level. |
|
| 1002 | + if ( empty( $this->orig_args ) ) { |
|
| 1003 | + $this->orig_args = $this->parent->args; |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + if ( isset( $box['args'] ) ) { |
|
| 1007 | + $this->parent->args = wp_parse_args( $box['args'], $this->orig_args ); |
|
| 1008 | + } elseif ( $this->parent->args !== $this->orig_args ) { |
|
| 1009 | + $this->parent->args = $this->orig_args; |
|
| 1010 | + } |
|
| 1011 | + |
|
| 1012 | + add_filter( 'postbox_classes_' . $posttype . '_redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id'], array( $this, 'add_box_classes' ) ); |
|
| 1013 | + |
|
| 1014 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1015 | + do_action( 'redux/' . $this->parent->args['opt_name'] . '/extensions/metabox/add', $this, $box, $posttype ); |
|
| 1016 | + |
|
| 1017 | + if ( isset( $box['post_format'] ) ) { |
|
| 1018 | + add_filter( 'postbox_classes_' . $posttype . '_redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id'], array( $this, 'add_box_hide_class' ) ); |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + // phpcs:ignore Generic.Strings.UnnecessaryStringConcat |
|
| 1022 | + call_user_func( 'add' . '_meta' . '_box', 'redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id'], $title, array( $this, 'generate_boxes' ), $posttype, $box['position'], $box['priority'], $args ); |
|
| 1023 | + } |
|
| 1024 | + } |
|
| 1025 | + } |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + /** |
|
| 1029 | + * Add hidden class to metabox DIV. |
|
| 1030 | + * |
|
| 1031 | + * @param array $classes Class array. |
|
| 1032 | + * |
|
| 1033 | + * @return array |
|
| 1034 | + */ |
|
| 1035 | + public function add_box_hide_class( array $classes ): array { |
|
| 1036 | + $classes[] = 'hide'; |
|
| 1037 | + |
|
| 1038 | + return $classes; |
|
| 1039 | + } |
|
| 1040 | + |
|
| 1041 | + /** |
|
| 1042 | + * Field Defaults. |
|
| 1043 | + * |
|
| 1044 | + * @param mixed $field_id ID. |
|
| 1045 | + * |
|
| 1046 | + * @return mixed|string |
|
| 1047 | + */ |
|
| 1048 | + private function field_default( $field_id ) { |
|
| 1049 | + if ( ! isset( $this->parent->options_defaults ) ) { |
|
| 1050 | + $this->parent->options_defaults = $this->parent->default_values(); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + if ( ! isset( $this->parent->options ) || empty( $this->parent->options ) ) { |
|
| 1054 | + if ( ! isset( $this->parent->options_class ) ) { |
|
| 1055 | + $this->parent->options_class = new Redux_Options_Constructor( $this->parent ); |
|
| 1056 | + } |
|
| 1057 | + |
|
| 1058 | + $this->parent->options_class->get(); |
|
| 1059 | + } |
|
| 1060 | + |
|
| 1061 | + $this->options = $this->parent->options; |
|
| 1062 | + |
|
| 1063 | + if ( isset( $this->parent->options[ $field_id['id'] ] ) && isset( $this->parent->options_defaults[ $field_id['id'] ] ) && $this->parent->options[ $field_id['id'] ] !== $this->parent->options_defaults[ $field_id['id'] ] ) { |
|
| 1064 | + return $this->parent->options[ $field_id['id'] ]; |
|
| 1065 | + } else { |
|
| 1066 | + if ( empty( $this->options_defaults ) ) { |
|
| 1067 | + $this->default_values(); // fill cache. |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + $data = ''; |
|
| 1071 | + if ( ! empty( $this->options_defaults ) ) { |
|
| 1072 | + $data = $this->options_defaults[ $field_id['id'] ] ?? ''; |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + if ( empty( $data ) && isset( $this->parent->options_defaults[ $field_id['id'] ] ) ) { |
|
| 1076 | + $data = $this->parent->options_defaults[ $field_id['id'] ] ?? ''; |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + return $data; |
|
| 1080 | + } |
|
| 1081 | + } |
|
| 1082 | + |
|
| 1083 | + /** |
|
| 1084 | + * Function to get and cache the post meta. |
|
| 1085 | + * |
|
| 1086 | + * @param mixed $id ID. |
|
| 1087 | + * |
|
| 1088 | + * @return array |
|
| 1089 | + */ |
|
| 1090 | + private function get_meta( $id ): array { |
|
| 1091 | + if ( ! isset( $this->meta[ $id ] ) ) { |
|
| 1092 | + $this->meta[ $id ] = array(); |
|
| 1093 | + $o_data = get_post_meta( $id ); |
|
| 1094 | + |
|
| 1095 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1096 | + $o_data = apply_filters( "redux/metaboxes/{$this->parent->args['opt_name']}/get_meta", $o_data ); |
|
| 1097 | + |
|
| 1098 | + if ( ! empty( $o_data ) ) { |
|
| 1099 | + foreach ( $o_data as $key => $value ) { |
|
| 1100 | + if ( 1 === count( $value ) ) { |
|
| 1101 | + $this->meta[ $id ][ $key ] = maybe_unserialize( $value[0] ); |
|
| 1102 | + } else { |
|
| 1103 | + $new_value = array_map( 'maybe_unserialize', $value ); |
|
| 1104 | + |
|
| 1105 | + $this->meta[ $id ][ $key ] = $new_value[0]; |
|
| 1106 | + } |
|
| 1107 | + } |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + if ( isset( $this->meta[ $id ][ $this->parent->args['opt_name'] ] ) ) { |
|
| 1111 | + $data = maybe_unserialize( $this->meta[ $id ][ $this->parent->args['opt_name'] ] ); |
|
| 1112 | + |
|
| 1113 | + foreach ( $data as $key => $value ) { |
|
| 1114 | + $this->meta[ $id ][ $key ] = $value; |
|
| 1115 | + update_post_meta( $id, $key, $value ); |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + unset( $this->meta[ $id ][ $this->parent->args['opt_name'] ] ); |
|
| 1119 | + |
|
| 1120 | + delete_post_meta( $id, $this->parent->args['opt_name'] ); |
|
| 1121 | + } |
|
| 1122 | + } |
|
| 1123 | + |
|
| 1124 | + return $this->meta[ $id ]; |
|
| 1125 | + } |
|
| 1126 | + |
|
| 1127 | + /** |
|
| 1128 | + * Get values. |
|
| 1129 | + * |
|
| 1130 | + * @param mixed $the_post Post object/id. |
|
| 1131 | + * @param string $meta_key Meta key. |
|
| 1132 | + * @param mixed $def_val Def value. |
|
| 1133 | + * |
|
| 1134 | + * @return array|mixed|string |
|
| 1135 | + */ |
|
| 1136 | + public function get_values( $the_post, string $meta_key = '', $def_val = '' ) { |
|
| 1137 | + |
|
| 1138 | + // Override these values if they differ from the admin panel defaults. ;) . |
|
| 1139 | + if ( isset( $the_post->post_type ) && in_array( $the_post->post_type, $this->post_types, true ) ) { |
|
| 1140 | + if ( isset( $this->post_type_values[ $the_post->post_type ] ) ) { |
|
| 1141 | + $meta = $this->post_type_fields[ $the_post->post_type ]; |
|
| 1142 | + } else { |
|
| 1143 | + $defaults = array(); |
|
| 1144 | + if ( ! empty( $this->post_type_fields[ $the_post->post_type ] ) ) { |
|
| 1145 | + foreach ( $this->post_type_fields[ $the_post->post_type ] as $key => $null ) { |
|
| 1146 | + if ( isset( $this->options_defaults[ $key ] ) ) { |
|
| 1147 | + $defaults[ $key ] = $this->options_defaults[ $key ]; |
|
| 1148 | + } |
|
| 1149 | + } |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + $meta = wp_parse_args( $this->get_meta( $the_post->ID ), $defaults ); |
|
| 1153 | + |
|
| 1154 | + $this->post_type_fields[ $the_post->post_type ] = $meta; |
|
| 1155 | + } |
|
| 1156 | + |
|
| 1157 | + if ( ! empty( $meta_key ) ) { |
|
| 1158 | + if ( ! isset( $meta[ $meta_key ] ) ) { |
|
| 1159 | + $meta[ $meta_key ] = $def_val; |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + return $meta[ $meta_key ]; |
|
| 1163 | + } else { |
|
| 1164 | + return $meta; |
|
| 1165 | + } |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + return $def_val; |
|
| 1169 | + } |
|
| 1170 | + |
|
| 1171 | + /** |
|
| 1172 | + * Generate Boxes. |
|
| 1173 | + * |
|
| 1174 | + * @param mixed $post Post. |
|
| 1175 | + * @param array $metabox Metabox array. |
|
| 1176 | + */ |
|
| 1177 | + public function generate_boxes( $post, array $metabox ) { |
|
| 1178 | + if ( ! empty( $metabox['args']['permissions'] ) && ! Redux_Helpers::current_user_can( $metabox['args']['permissions'] ) ) { |
|
| 1179 | + return; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + $sections = $metabox['args']['sections']; |
|
| 1183 | + |
|
| 1184 | + wp_nonce_field( 'redux_metaboxes_meta_nonce', 'redux_metaboxes_meta_nonce' ); |
|
| 1185 | + |
|
| 1186 | + wp_dequeue_script( 'json-view-js' ); |
|
| 1187 | + |
|
| 1188 | + $sidebar = true; |
|
| 1189 | + |
|
| 1190 | + if ( 'side' === $metabox['args']['position'] || 1 === count( $sections ) || ( isset( $metabox['args']['sidebar'] ) && false === $metabox['args']['sidebar'] ) ) { |
|
| 1191 | + $sidebar = false; // Show the section dividers or not. |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + ?> |
|
| 1195 | 1195 | <input |
| 1196 | 1196 | type="hidden" |
| 1197 | 1197 | id="currentSection" |
@@ -1221,21 +1221,21 @@ discard block |
||
| 1221 | 1221 | </div> |
| 1222 | 1222 | </div> |
| 1223 | 1223 | <?php |
| 1224 | - echo '<a href="javascript:void(0);" class="expand_options hide" style="display:none;">' . esc_html__( 'Expand', 'redux-framework' ) . '</a>'; |
|
| 1225 | - if ( $sidebar ) { |
|
| 1226 | - ?> |
|
| 1224 | + echo '<a href="javascript:void(0);" class="expand_options hide" style="display:none;">' . esc_html__( 'Expand', 'redux-framework' ) . '</a>'; |
|
| 1225 | + if ( $sidebar ) { |
|
| 1226 | + ?> |
|
| 1227 | 1227 | <div class="redux-sidebar"> |
| 1228 | 1228 | <ul class="redux-group-menu"> |
| 1229 | 1229 | <?php |
| 1230 | 1230 | |
| 1231 | - foreach ( $sections as $s_key => $section ) { |
|
| 1232 | - if ( ! empty( $section['permissions'] ) && ! Redux_Helpers::current_user_can( $section['permissions'] ) ) { |
|
| 1233 | - continue; |
|
| 1234 | - } |
|
| 1231 | + foreach ( $sections as $s_key => $section ) { |
|
| 1232 | + if ( ! empty( $section['permissions'] ) && ! Redux_Helpers::current_user_can( $section['permissions'] ) ) { |
|
| 1233 | + continue; |
|
| 1234 | + } |
|
| 1235 | 1235 | |
| 1236 | - echo $this->parent->render_class->section_menu( $s_key, $section, '_box_' . $metabox['id'], $sections ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1237 | - } |
|
| 1238 | - ?> |
|
| 1236 | + echo $this->parent->render_class->section_menu( $s_key, $section, '_box_' . $metabox['id'], $sections ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1237 | + } |
|
| 1238 | + ?> |
|
| 1239 | 1239 | </ul> |
| 1240 | 1240 | </div> |
| 1241 | 1241 | <?php } ?> |
@@ -1243,295 +1243,295 @@ discard block |
||
| 1243 | 1243 | <div class="redux-main"> |
| 1244 | 1244 | <?php |
| 1245 | 1245 | |
| 1246 | - foreach ( $sections as $s_key => $section ) { |
|
| 1247 | - if ( ! empty( $section['permissions'] ) && ! Redux_Helpers::current_user_can( $section['permissions'] ) ) { |
|
| 1248 | - continue; |
|
| 1249 | - } |
|
| 1250 | - if ( ! empty( $section['fields'] ) ) { |
|
| 1251 | - if ( isset( $section['args'] ) ) { |
|
| 1252 | - $this->parent->args = wp_parse_args( $section['args'], $this->orig_args ); |
|
| 1253 | - } elseif ( $this->parent->args !== $this->orig_args ) { |
|
| 1254 | - $this->parent->args = $this->orig_args; |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - $hide = $sidebar ? '' : ' display-group'; |
|
| 1258 | - $section['class'] = isset( $section['class'] ) ? ' ' . $section['class'] : ''; |
|
| 1259 | - echo '<div id="' . esc_attr( $s_key ) . '_box_' . esc_attr( $metabox['id'] ) . '_section_group" class="redux-group-tab' . esc_attr( $section['class'] ) . ' redux_metabox_panel' . esc_attr( $hide ) . '">'; |
|
| 1260 | - |
|
| 1261 | - if ( ! empty( $section['title'] ) ) { |
|
| 1262 | - echo '<h3 class="redux-section-title">' . wp_kses_post( $section['title'] ) . '</h3>'; |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - if ( ! empty( $section['desc'] ) ) { |
|
| 1266 | - echo '<div class="redux-section-desc">' . wp_kses_post( $section['desc'] ) . '</div>'; |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - echo '<table class="form-table"><tbody>'; |
|
| 1270 | - foreach ( $section['fields'] as $field ) { |
|
| 1271 | - if ( ! empty( $field['permissions'] ) && ! Redux_Helpers::current_user_can( $field['permissions'] ) ) { |
|
| 1272 | - continue; |
|
| 1273 | - } |
|
| 1274 | - $field['name'] = $this->parent->args['opt_name'] . '[' . $field['id'] . ']'; |
|
| 1275 | - |
|
| 1276 | - $is_hidden = false; |
|
| 1277 | - $ex_style = ''; |
|
| 1278 | - if ( isset( $field['hidden'] ) && $field['hidden'] ) { |
|
| 1279 | - $is_hidden = true; |
|
| 1280 | - $ex_style = ' style="border-bottom: none;"'; |
|
| 1281 | - } |
|
| 1282 | - |
|
| 1283 | - echo '<tr valign="top"' . $ex_style . '>'; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1284 | - |
|
| 1285 | - $th = $this->parent->render_class->get_header_html( $field ); |
|
| 1286 | - |
|
| 1287 | - if ( $is_hidden ) { |
|
| 1288 | - $str_pos = strpos( $th, 'redux_field_th' ); |
|
| 1289 | - |
|
| 1290 | - if ( $str_pos > - 1 ) { |
|
| 1291 | - $th = str_replace( 'redux_field_th', 'redux_field_th hide', $th ); |
|
| 1292 | - } |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - if ( $sidebar ) { |
|
| 1296 | - if ( ! ( isset( $metabox['args']['sections'] ) && 1 === count( $metabox['args']['sections'] ) && isset( $metabox['args']['sections'][0]['fields'] ) && 1 === count( $metabox['args']['sections'][0]['fields'] ) ) && isset( $field['title'] ) ) { |
|
| 1297 | - echo '<th scope="row">'; |
|
| 1298 | - if ( ! empty( $th ) ) { |
|
| 1299 | - echo $th; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1300 | - } |
|
| 1301 | - echo '</th>'; |
|
| 1302 | - echo '<td>'; |
|
| 1303 | - } |
|
| 1304 | - } else { |
|
| 1305 | - echo '<td>' . $th; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - if ( 'section' === $field['type'] && ( 'true' === $field['indent'] || true === $field['indent'] ) ) { |
|
| 1309 | - $field['class'] = $field['class'] ?? ''; |
|
| 1310 | - $field['class'] .= 'redux-section-indent-start'; |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - if ( ! isset( $this->meta[ $this->post_id ][ $field['id'] ] ) ) { |
|
| 1314 | - $this->meta[ $this->post_id ][ $field['id'] ] = ''; |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - $this->parent->render_class->field_input( $field, $this->meta[ $this->post_id ][ $field['id'] ], true ); |
|
| 1318 | - echo '</td></tr>'; |
|
| 1319 | - } |
|
| 1320 | - echo '</tbody></table>'; |
|
| 1321 | - echo '</div>'; |
|
| 1322 | - } |
|
| 1323 | - } |
|
| 1324 | - ?> |
|
| 1246 | + foreach ( $sections as $s_key => $section ) { |
|
| 1247 | + if ( ! empty( $section['permissions'] ) && ! Redux_Helpers::current_user_can( $section['permissions'] ) ) { |
|
| 1248 | + continue; |
|
| 1249 | + } |
|
| 1250 | + if ( ! empty( $section['fields'] ) ) { |
|
| 1251 | + if ( isset( $section['args'] ) ) { |
|
| 1252 | + $this->parent->args = wp_parse_args( $section['args'], $this->orig_args ); |
|
| 1253 | + } elseif ( $this->parent->args !== $this->orig_args ) { |
|
| 1254 | + $this->parent->args = $this->orig_args; |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + $hide = $sidebar ? '' : ' display-group'; |
|
| 1258 | + $section['class'] = isset( $section['class'] ) ? ' ' . $section['class'] : ''; |
|
| 1259 | + echo '<div id="' . esc_attr( $s_key ) . '_box_' . esc_attr( $metabox['id'] ) . '_section_group" class="redux-group-tab' . esc_attr( $section['class'] ) . ' redux_metabox_panel' . esc_attr( $hide ) . '">'; |
|
| 1260 | + |
|
| 1261 | + if ( ! empty( $section['title'] ) ) { |
|
| 1262 | + echo '<h3 class="redux-section-title">' . wp_kses_post( $section['title'] ) . '</h3>'; |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + if ( ! empty( $section['desc'] ) ) { |
|
| 1266 | + echo '<div class="redux-section-desc">' . wp_kses_post( $section['desc'] ) . '</div>'; |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + echo '<table class="form-table"><tbody>'; |
|
| 1270 | + foreach ( $section['fields'] as $field ) { |
|
| 1271 | + if ( ! empty( $field['permissions'] ) && ! Redux_Helpers::current_user_can( $field['permissions'] ) ) { |
|
| 1272 | + continue; |
|
| 1273 | + } |
|
| 1274 | + $field['name'] = $this->parent->args['opt_name'] . '[' . $field['id'] . ']'; |
|
| 1275 | + |
|
| 1276 | + $is_hidden = false; |
|
| 1277 | + $ex_style = ''; |
|
| 1278 | + if ( isset( $field['hidden'] ) && $field['hidden'] ) { |
|
| 1279 | + $is_hidden = true; |
|
| 1280 | + $ex_style = ' style="border-bottom: none;"'; |
|
| 1281 | + } |
|
| 1282 | + |
|
| 1283 | + echo '<tr valign="top"' . $ex_style . '>'; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1284 | + |
|
| 1285 | + $th = $this->parent->render_class->get_header_html( $field ); |
|
| 1286 | + |
|
| 1287 | + if ( $is_hidden ) { |
|
| 1288 | + $str_pos = strpos( $th, 'redux_field_th' ); |
|
| 1289 | + |
|
| 1290 | + if ( $str_pos > - 1 ) { |
|
| 1291 | + $th = str_replace( 'redux_field_th', 'redux_field_th hide', $th ); |
|
| 1292 | + } |
|
| 1293 | + } |
|
| 1294 | + |
|
| 1295 | + if ( $sidebar ) { |
|
| 1296 | + if ( ! ( isset( $metabox['args']['sections'] ) && 1 === count( $metabox['args']['sections'] ) && isset( $metabox['args']['sections'][0]['fields'] ) && 1 === count( $metabox['args']['sections'][0]['fields'] ) ) && isset( $field['title'] ) ) { |
|
| 1297 | + echo '<th scope="row">'; |
|
| 1298 | + if ( ! empty( $th ) ) { |
|
| 1299 | + echo $th; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1300 | + } |
|
| 1301 | + echo '</th>'; |
|
| 1302 | + echo '<td>'; |
|
| 1303 | + } |
|
| 1304 | + } else { |
|
| 1305 | + echo '<td>' . $th; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + if ( 'section' === $field['type'] && ( 'true' === $field['indent'] || true === $field['indent'] ) ) { |
|
| 1309 | + $field['class'] = $field['class'] ?? ''; |
|
| 1310 | + $field['class'] .= 'redux-section-indent-start'; |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + if ( ! isset( $this->meta[ $this->post_id ][ $field['id'] ] ) ) { |
|
| 1314 | + $this->meta[ $this->post_id ][ $field['id'] ] = ''; |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + $this->parent->render_class->field_input( $field, $this->meta[ $this->post_id ][ $field['id'] ], true ); |
|
| 1318 | + echo '</td></tr>'; |
|
| 1319 | + } |
|
| 1320 | + echo '</tbody></table>'; |
|
| 1321 | + echo '</div>'; |
|
| 1322 | + } |
|
| 1323 | + } |
|
| 1324 | + ?> |
|
| 1325 | 1325 | </div> |
| 1326 | 1326 | <div class="clear"></div> |
| 1327 | 1327 | </div> |
| 1328 | 1328 | <?php |
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - /** |
|
| 1332 | - * Save meta boxes |
|
| 1333 | - * Runs when a post is saved and does an action which the write panel save scripts can hook into. |
|
| 1334 | - * |
|
| 1335 | - * @access public |
|
| 1336 | - * |
|
| 1337 | - * @param mixed $post_id Post ID. |
|
| 1338 | - * @param mixed $post Post. |
|
| 1339 | - * |
|
| 1340 | - * @return mixed |
|
| 1341 | - */ |
|
| 1342 | - public function meta_boxes_save( $post_id, $post ) { |
|
| 1343 | - if ( isset( $_POST['vc_inline'] ) && sanitize_text_field( wp_unslash( $_POST['vc_inline'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1344 | - return $post_id; |
|
| 1345 | - } |
|
| 1346 | - |
|
| 1347 | - if ( isset( $_POST['post_ID'] ) && strval( $post_id ) !== $_POST['post_ID'] ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1348 | - return $post_id; |
|
| 1349 | - } |
|
| 1350 | - |
|
| 1351 | - // Check if our nonce is set. |
|
| 1352 | - if ( ! isset( $_POST['redux_metaboxes_meta_nonce'] ) || ! isset( $_POST[ $this->parent->args['opt_name'] ] ) ) { |
|
| 1353 | - return $post_id; |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - // Verify that the nonce is valid. |
|
| 1357 | - // Validate fields (if needed). |
|
| 1358 | - if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['redux_metaboxes_meta_nonce'] ) ), 'redux_metaboxes_meta_nonce' ) ) { |
|
| 1359 | - return $post_id; |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - // If this is an autosave, our form has not been submitted, so we don't want to do anything. |
|
| 1363 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
| 1364 | - return $post_id; |
|
| 1365 | - } |
|
| 1366 | - |
|
| 1367 | - // Check the user's permissions, even allowing custom capabilities. |
|
| 1368 | - $obj = get_post_type_object( $post->post_type ); |
|
| 1369 | - if ( ! current_user_can( $obj->cap->edit_post, $post_id ) ) { |
|
| 1370 | - return $post_id; |
|
| 1371 | - } |
|
| 1372 | - |
|
| 1373 | - // Import. |
|
| 1374 | - if ( isset( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ) && ! empty( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ) ) { |
|
| 1375 | - $import = json_decode( sanitize_text_field( wp_unslash( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ) ), true ); |
|
| 1376 | - unset( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ); |
|
| 1377 | - |
|
| 1378 | - foreach ( Redux_Helpers::sanitize_array( wp_unslash( $_POST[ $this->parent->args['opt_name'] ] ) ) as $key => $value ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput |
|
| 1379 | - if ( ! isset( $import[ $key ] ) ) { |
|
| 1380 | - $import[ $key ] = $value; |
|
| 1381 | - } |
|
| 1382 | - } |
|
| 1383 | - |
|
| 1384 | - $_POST[ $this->parent->args['opt_name'] ] = $import; |
|
| 1385 | - } |
|
| 1386 | - |
|
| 1387 | - $to_save = array(); |
|
| 1388 | - $to_compare = array(); |
|
| 1389 | - $to_delete = array(); |
|
| 1390 | - $dont_save = true; |
|
| 1391 | - |
|
| 1392 | - if ( isset( $this->parent->args['metaboxes_save_defaults'] ) && $this->parent->args['metaboxes_save_defaults'] ) { |
|
| 1393 | - $dont_save = false; |
|
| 1394 | - } |
|
| 1395 | - |
|
| 1396 | - foreach ( Redux_Helpers::sanitize_array( wp_unslash( $_POST[ $this->parent->args['opt_name'] ] ) ) as $key => $value ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput |
|
| 1397 | - |
|
| 1398 | - // Have to remove the escaping for array comparison. |
|
| 1399 | - if ( is_array( $value ) ) { |
|
| 1400 | - foreach ( $value as $k => $v ) { |
|
| 1401 | - if ( ! is_array( $v ) ) { |
|
| 1402 | - $value[ $k ] = wp_unslash( $v ); |
|
| 1403 | - } |
|
| 1404 | - } |
|
| 1405 | - } |
|
| 1406 | - |
|
| 1407 | - $save = true; |
|
| 1408 | - |
|
| 1409 | - // parent_options. |
|
| 1410 | - if ( ! $dont_save && isset( $this->options_defaults[ $key ] ) && $value === $this->options_defaults[ $key ] ) { |
|
| 1411 | - $save = false; |
|
| 1412 | - } |
|
| 1413 | - |
|
| 1414 | - if ( $save && isset( $this->parent_options[ $key ] ) && $this->parent_options[ $key ] !== $value ) { |
|
| 1415 | - $save = false; |
|
| 1416 | - } |
|
| 1417 | - |
|
| 1418 | - if ( $save ) { |
|
| 1419 | - $to_save[ $key ] = $value; |
|
| 1420 | - $to_compare[ $key ] = $this->parent->options[ $key ] ?? ''; |
|
| 1421 | - } else { |
|
| 1422 | - $to_delete[ $key ] = $value; |
|
| 1423 | - } |
|
| 1424 | - } |
|
| 1425 | - |
|
| 1426 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1427 | - $to_save = apply_filters( 'redux/metaboxes/save/before_validate', $to_save, $to_compare, $this->sections ); |
|
| 1428 | - |
|
| 1429 | - $validate = $this->parent->validate_class->validate( $to_save, $to_compare, $this->sections ); |
|
| 1430 | - |
|
| 1431 | - // Validate fields (if needed). |
|
| 1432 | - foreach ( $to_save as $key => $value ) { |
|
| 1433 | - if ( isset( $validate[ $key ] ) && $value !== $validate[ $key ] ) { |
|
| 1434 | - if ( isset( $this->parent->options[ $key ] ) && $validate[ $key ] === $this->parent->options[ $key ] ) { |
|
| 1435 | - unset( $to_save[ $key ] ); |
|
| 1436 | - } else { |
|
| 1437 | - $to_save[ $key ] = $validate[ $key ]; |
|
| 1438 | - } |
|
| 1439 | - } |
|
| 1440 | - } |
|
| 1441 | - |
|
| 1442 | - if ( ! empty( $this->parent->errors ) || ! empty( $this->parent->warnings ) ) { |
|
| 1443 | - $this->parent->transients['notices'] = ( isset( $this->parent->transients['notices'] ) && is_array( $this->parent->transients['notices'] ) ) ? $this->parent->transients['notices'] : array(); |
|
| 1444 | - |
|
| 1445 | - if ( ! isset( $this->parent->transients['notices']['errors'] ) || $this->parent->transients['notices']['errors'] !== $this->parent->errors ) { |
|
| 1446 | - $this->parent->transients['notices']['errors'] = $this->parent->errors; |
|
| 1447 | - $update_transients = true; |
|
| 1448 | - } |
|
| 1449 | - |
|
| 1450 | - if ( ! isset( $this->parent->transients['notices']['warnings'] ) || $this->parent->transients['notices']['warnings'] !== $this->parent->warnings ) { |
|
| 1451 | - $this->parent->transients['notices']['warnings'] = $this->parent->warnings; |
|
| 1452 | - $update_transients = true; |
|
| 1453 | - } |
|
| 1454 | - |
|
| 1455 | - if ( isset( $update_transients ) ) { |
|
| 1456 | - $this->parent->transients['notices']['override'] = 1; |
|
| 1457 | - set_transient( $this->parent->args['opt_name'] . '-transients-metaboxes', $this->parent->transients ); |
|
| 1458 | - } |
|
| 1459 | - } |
|
| 1460 | - |
|
| 1461 | - if ( isset( $_POST['post_type'] ) ) { |
|
| 1462 | - $check = $this->post_type_fields[ sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) ]; |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1466 | - $to_save = apply_filters( 'redux/metaboxes/save', $to_save, $to_compare, $this->sections ); |
|
| 1467 | - |
|
| 1468 | - foreach ( $to_save as $key => $value ) { |
|
| 1469 | - $prev_value = $this->meta[ $post_id ][ $key ] ?? ''; |
|
| 1470 | - |
|
| 1471 | - if ( isset( $check[ $key ] ) ) { |
|
| 1472 | - unset( $check[ $key ] ); |
|
| 1473 | - } |
|
| 1474 | - |
|
| 1475 | - update_post_meta( $post_id, $key, $value, $prev_value ); |
|
| 1476 | - } |
|
| 1477 | - |
|
| 1478 | - foreach ( $to_delete as $key => $value ) { |
|
| 1479 | - if ( isset( $check[ $key ] ) ) { |
|
| 1480 | - unset( $check[ $key ] ); |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - $prev_value = $this->meta[ $post_id ][ $key ] ?? ''; |
|
| 1484 | - delete_post_meta( $post_id, $key, $prev_value ); |
|
| 1485 | - } |
|
| 1486 | - |
|
| 1487 | - if ( ! empty( $check ) ) { |
|
| 1488 | - foreach ( $check as $key => $value ) { |
|
| 1489 | - delete_post_meta( $post_id, $key ); |
|
| 1490 | - } |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - return $post_id; |
|
| 1494 | - } |
|
| 1495 | - |
|
| 1496 | - /** |
|
| 1497 | - * Some functions, like the term recount, require the visibility to be set prior. Lets save that here. |
|
| 1498 | - * |
|
| 1499 | - * @access public |
|
| 1500 | - * |
|
| 1501 | - * @param mixed $post_id Post ID. |
|
| 1502 | - * |
|
| 1503 | - * @return void |
|
| 1504 | - */ |
|
| 1505 | - public function pre_post_update( $post_id ) { |
|
| 1506 | - if ( isset( $_POST['_visibility'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1507 | - update_post_meta( $post_id, '_visibility', sanitize_text_field( wp_unslash( $_POST['_visibility'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1508 | - } |
|
| 1509 | - |
|
| 1510 | - if ( isset( $_POST['_stock_status'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1511 | - update_post_meta( $post_id, '_stock_status', sanitize_text_field( wp_unslash( $_POST['_stock_status'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1512 | - } |
|
| 1513 | - } |
|
| 1514 | - |
|
| 1515 | - /** |
|
| 1516 | - * Show any stored error messages. |
|
| 1517 | - * |
|
| 1518 | - * @access public |
|
| 1519 | - * @return void |
|
| 1520 | - */ |
|
| 1521 | - public function meta_boxes_show_errors() { |
|
| 1522 | - if ( isset( $this->notices['errors'] ) && ! empty( $this->notices['errors'] ) ) { |
|
| 1523 | - echo '<div id="redux_metaboxes_errors" class="error fade">'; |
|
| 1524 | - echo '<p><strong><span></span> ' . count( $this->notices['errors'] ) . ' ' . esc_html__( 'error(s) were found!', 'redux-framework' ) . '</strong></p>'; |
|
| 1525 | - echo '</div>'; |
|
| 1526 | - } |
|
| 1527 | - |
|
| 1528 | - if ( isset( $this->notices['warnings'] ) && ! empty( $this->notices['warnings'] ) ) { |
|
| 1529 | - echo '<div id="redux_metaboxes_warnings" class="error fade" style="border-left-color: #E8E20C;">'; |
|
| 1530 | - echo '<p><strong><span></span> ' . count( $this->notices['warnings'] ) . ' ' . esc_html__( 'warnings(s) were found!', 'redux-framework' ) . '</strong></p>'; |
|
| 1531 | - echo '</div>'; |
|
| 1532 | - } |
|
| 1533 | - } |
|
| 1534 | - } |
|
| 1535 | - |
|
| 1536 | - class_alias( Redux_Extension_Metaboxes::class, 'ReduxFramework_Extension_metaboxes' ); |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + /** |
|
| 1332 | + * Save meta boxes |
|
| 1333 | + * Runs when a post is saved and does an action which the write panel save scripts can hook into. |
|
| 1334 | + * |
|
| 1335 | + * @access public |
|
| 1336 | + * |
|
| 1337 | + * @param mixed $post_id Post ID. |
|
| 1338 | + * @param mixed $post Post. |
|
| 1339 | + * |
|
| 1340 | + * @return mixed |
|
| 1341 | + */ |
|
| 1342 | + public function meta_boxes_save( $post_id, $post ) { |
|
| 1343 | + if ( isset( $_POST['vc_inline'] ) && sanitize_text_field( wp_unslash( $_POST['vc_inline'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1344 | + return $post_id; |
|
| 1345 | + } |
|
| 1346 | + |
|
| 1347 | + if ( isset( $_POST['post_ID'] ) && strval( $post_id ) !== $_POST['post_ID'] ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1348 | + return $post_id; |
|
| 1349 | + } |
|
| 1350 | + |
|
| 1351 | + // Check if our nonce is set. |
|
| 1352 | + if ( ! isset( $_POST['redux_metaboxes_meta_nonce'] ) || ! isset( $_POST[ $this->parent->args['opt_name'] ] ) ) { |
|
| 1353 | + return $post_id; |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + // Verify that the nonce is valid. |
|
| 1357 | + // Validate fields (if needed). |
|
| 1358 | + if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['redux_metaboxes_meta_nonce'] ) ), 'redux_metaboxes_meta_nonce' ) ) { |
|
| 1359 | + return $post_id; |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + // If this is an autosave, our form has not been submitted, so we don't want to do anything. |
|
| 1363 | + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
| 1364 | + return $post_id; |
|
| 1365 | + } |
|
| 1366 | + |
|
| 1367 | + // Check the user's permissions, even allowing custom capabilities. |
|
| 1368 | + $obj = get_post_type_object( $post->post_type ); |
|
| 1369 | + if ( ! current_user_can( $obj->cap->edit_post, $post_id ) ) { |
|
| 1370 | + return $post_id; |
|
| 1371 | + } |
|
| 1372 | + |
|
| 1373 | + // Import. |
|
| 1374 | + if ( isset( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ) && ! empty( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ) ) { |
|
| 1375 | + $import = json_decode( sanitize_text_field( wp_unslash( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ) ), true ); |
|
| 1376 | + unset( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ); |
|
| 1377 | + |
|
| 1378 | + foreach ( Redux_Helpers::sanitize_array( wp_unslash( $_POST[ $this->parent->args['opt_name'] ] ) ) as $key => $value ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput |
|
| 1379 | + if ( ! isset( $import[ $key ] ) ) { |
|
| 1380 | + $import[ $key ] = $value; |
|
| 1381 | + } |
|
| 1382 | + } |
|
| 1383 | + |
|
| 1384 | + $_POST[ $this->parent->args['opt_name'] ] = $import; |
|
| 1385 | + } |
|
| 1386 | + |
|
| 1387 | + $to_save = array(); |
|
| 1388 | + $to_compare = array(); |
|
| 1389 | + $to_delete = array(); |
|
| 1390 | + $dont_save = true; |
|
| 1391 | + |
|
| 1392 | + if ( isset( $this->parent->args['metaboxes_save_defaults'] ) && $this->parent->args['metaboxes_save_defaults'] ) { |
|
| 1393 | + $dont_save = false; |
|
| 1394 | + } |
|
| 1395 | + |
|
| 1396 | + foreach ( Redux_Helpers::sanitize_array( wp_unslash( $_POST[ $this->parent->args['opt_name'] ] ) ) as $key => $value ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput |
|
| 1397 | + |
|
| 1398 | + // Have to remove the escaping for array comparison. |
|
| 1399 | + if ( is_array( $value ) ) { |
|
| 1400 | + foreach ( $value as $k => $v ) { |
|
| 1401 | + if ( ! is_array( $v ) ) { |
|
| 1402 | + $value[ $k ] = wp_unslash( $v ); |
|
| 1403 | + } |
|
| 1404 | + } |
|
| 1405 | + } |
|
| 1406 | + |
|
| 1407 | + $save = true; |
|
| 1408 | + |
|
| 1409 | + // parent_options. |
|
| 1410 | + if ( ! $dont_save && isset( $this->options_defaults[ $key ] ) && $value === $this->options_defaults[ $key ] ) { |
|
| 1411 | + $save = false; |
|
| 1412 | + } |
|
| 1413 | + |
|
| 1414 | + if ( $save && isset( $this->parent_options[ $key ] ) && $this->parent_options[ $key ] !== $value ) { |
|
| 1415 | + $save = false; |
|
| 1416 | + } |
|
| 1417 | + |
|
| 1418 | + if ( $save ) { |
|
| 1419 | + $to_save[ $key ] = $value; |
|
| 1420 | + $to_compare[ $key ] = $this->parent->options[ $key ] ?? ''; |
|
| 1421 | + } else { |
|
| 1422 | + $to_delete[ $key ] = $value; |
|
| 1423 | + } |
|
| 1424 | + } |
|
| 1425 | + |
|
| 1426 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1427 | + $to_save = apply_filters( 'redux/metaboxes/save/before_validate', $to_save, $to_compare, $this->sections ); |
|
| 1428 | + |
|
| 1429 | + $validate = $this->parent->validate_class->validate( $to_save, $to_compare, $this->sections ); |
|
| 1430 | + |
|
| 1431 | + // Validate fields (if needed). |
|
| 1432 | + foreach ( $to_save as $key => $value ) { |
|
| 1433 | + if ( isset( $validate[ $key ] ) && $value !== $validate[ $key ] ) { |
|
| 1434 | + if ( isset( $this->parent->options[ $key ] ) && $validate[ $key ] === $this->parent->options[ $key ] ) { |
|
| 1435 | + unset( $to_save[ $key ] ); |
|
| 1436 | + } else { |
|
| 1437 | + $to_save[ $key ] = $validate[ $key ]; |
|
| 1438 | + } |
|
| 1439 | + } |
|
| 1440 | + } |
|
| 1441 | + |
|
| 1442 | + if ( ! empty( $this->parent->errors ) || ! empty( $this->parent->warnings ) ) { |
|
| 1443 | + $this->parent->transients['notices'] = ( isset( $this->parent->transients['notices'] ) && is_array( $this->parent->transients['notices'] ) ) ? $this->parent->transients['notices'] : array(); |
|
| 1444 | + |
|
| 1445 | + if ( ! isset( $this->parent->transients['notices']['errors'] ) || $this->parent->transients['notices']['errors'] !== $this->parent->errors ) { |
|
| 1446 | + $this->parent->transients['notices']['errors'] = $this->parent->errors; |
|
| 1447 | + $update_transients = true; |
|
| 1448 | + } |
|
| 1449 | + |
|
| 1450 | + if ( ! isset( $this->parent->transients['notices']['warnings'] ) || $this->parent->transients['notices']['warnings'] !== $this->parent->warnings ) { |
|
| 1451 | + $this->parent->transients['notices']['warnings'] = $this->parent->warnings; |
|
| 1452 | + $update_transients = true; |
|
| 1453 | + } |
|
| 1454 | + |
|
| 1455 | + if ( isset( $update_transients ) ) { |
|
| 1456 | + $this->parent->transients['notices']['override'] = 1; |
|
| 1457 | + set_transient( $this->parent->args['opt_name'] . '-transients-metaboxes', $this->parent->transients ); |
|
| 1458 | + } |
|
| 1459 | + } |
|
| 1460 | + |
|
| 1461 | + if ( isset( $_POST['post_type'] ) ) { |
|
| 1462 | + $check = $this->post_type_fields[ sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) ]; |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1466 | + $to_save = apply_filters( 'redux/metaboxes/save', $to_save, $to_compare, $this->sections ); |
|
| 1467 | + |
|
| 1468 | + foreach ( $to_save as $key => $value ) { |
|
| 1469 | + $prev_value = $this->meta[ $post_id ][ $key ] ?? ''; |
|
| 1470 | + |
|
| 1471 | + if ( isset( $check[ $key ] ) ) { |
|
| 1472 | + unset( $check[ $key ] ); |
|
| 1473 | + } |
|
| 1474 | + |
|
| 1475 | + update_post_meta( $post_id, $key, $value, $prev_value ); |
|
| 1476 | + } |
|
| 1477 | + |
|
| 1478 | + foreach ( $to_delete as $key => $value ) { |
|
| 1479 | + if ( isset( $check[ $key ] ) ) { |
|
| 1480 | + unset( $check[ $key ] ); |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + $prev_value = $this->meta[ $post_id ][ $key ] ?? ''; |
|
| 1484 | + delete_post_meta( $post_id, $key, $prev_value ); |
|
| 1485 | + } |
|
| 1486 | + |
|
| 1487 | + if ( ! empty( $check ) ) { |
|
| 1488 | + foreach ( $check as $key => $value ) { |
|
| 1489 | + delete_post_meta( $post_id, $key ); |
|
| 1490 | + } |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + return $post_id; |
|
| 1494 | + } |
|
| 1495 | + |
|
| 1496 | + /** |
|
| 1497 | + * Some functions, like the term recount, require the visibility to be set prior. Lets save that here. |
|
| 1498 | + * |
|
| 1499 | + * @access public |
|
| 1500 | + * |
|
| 1501 | + * @param mixed $post_id Post ID. |
|
| 1502 | + * |
|
| 1503 | + * @return void |
|
| 1504 | + */ |
|
| 1505 | + public function pre_post_update( $post_id ) { |
|
| 1506 | + if ( isset( $_POST['_visibility'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1507 | + update_post_meta( $post_id, '_visibility', sanitize_text_field( wp_unslash( $_POST['_visibility'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1508 | + } |
|
| 1509 | + |
|
| 1510 | + if ( isset( $_POST['_stock_status'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1511 | + update_post_meta( $post_id, '_stock_status', sanitize_text_field( wp_unslash( $_POST['_stock_status'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1512 | + } |
|
| 1513 | + } |
|
| 1514 | + |
|
| 1515 | + /** |
|
| 1516 | + * Show any stored error messages. |
|
| 1517 | + * |
|
| 1518 | + * @access public |
|
| 1519 | + * @return void |
|
| 1520 | + */ |
|
| 1521 | + public function meta_boxes_show_errors() { |
|
| 1522 | + if ( isset( $this->notices['errors'] ) && ! empty( $this->notices['errors'] ) ) { |
|
| 1523 | + echo '<div id="redux_metaboxes_errors" class="error fade">'; |
|
| 1524 | + echo '<p><strong><span></span> ' . count( $this->notices['errors'] ) . ' ' . esc_html__( 'error(s) were found!', 'redux-framework' ) . '</strong></p>'; |
|
| 1525 | + echo '</div>'; |
|
| 1526 | + } |
|
| 1527 | + |
|
| 1528 | + if ( isset( $this->notices['warnings'] ) && ! empty( $this->notices['warnings'] ) ) { |
|
| 1529 | + echo '<div id="redux_metaboxes_warnings" class="error fade" style="border-left-color: #E8E20C;">'; |
|
| 1530 | + echo '<p><strong><span></span> ' . count( $this->notices['warnings'] ) . ' ' . esc_html__( 'warnings(s) were found!', 'redux-framework' ) . '</strong></p>'; |
|
| 1531 | + echo '</div>'; |
|
| 1532 | + } |
|
| 1533 | + } |
|
| 1534 | + } |
|
| 1535 | + |
|
| 1536 | + class_alias( Redux_Extension_Metaboxes::class, 'ReduxFramework_Extension_metaboxes' ); |
|
| 1537 | 1537 | } |