@@ -63,8 +63,9 @@ |
||
| 63 | 63 | |
| 64 | 64 | function lasso_editor_get_option( $option, $section, $default = '' ) { |
| 65 | 65 | |
| 66 | - if ( empty( $option ) ) |
|
| 67 | - return; |
|
| 66 | + if ( empty( $option ) ) { |
|
| 67 | + return; |
|
| 68 | + } |
|
| 68 | 69 | |
| 69 | 70 | if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
| 70 | 71 | |
@@ -61,6 +61,9 @@ |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | |
| 64 | +/** |
|
| 65 | + * @param string $section |
|
| 66 | + */ |
|
| 64 | 67 | function lasso_editor_get_option( $option, $section, $default = '' ) { |
| 65 | 68 | |
| 66 | 69 | if ( empty( $option ) ) |
@@ -18,27 +18,27 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | // If this file is called directly, abort. |
| 21 | -if ( ! defined( 'WPINC' ) ) { |
|
| 21 | +if (!defined('WPINC')) { |
|
| 22 | 22 | die; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | // Set some constants |
| 26 | -define( 'LASSO_VERSION', '1.1.3' ); |
|
| 27 | -define( 'LASSO_DIR', plugin_dir_path( __FILE__ ) ); |
|
| 28 | -define( 'LASSO_URL', plugins_url( '', __FILE__ ) ); |
|
| 29 | -define( 'LASSO_FILE', __FILE__ ); |
|
| 26 | +define('LASSO_VERSION', '1.1.3'); |
|
| 27 | +define('LASSO_DIR', plugin_dir_path(__FILE__)); |
|
| 28 | +define('LASSO_URL', plugins_url('', __FILE__)); |
|
| 29 | +define('LASSO_FILE', __FILE__); |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Load plugin if PHP version is 5.4 or later. |
| 33 | 33 | */ |
| 34 | -if ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ) { |
|
| 34 | +if (version_compare(PHP_VERSION, '5.4.0', '>=')) { |
|
| 35 | 35 | |
| 36 | - include_once( LASSO_DIR . '/bootstrap.php' ); |
|
| 36 | + include_once(LASSO_DIR.'/bootstrap.php'); |
|
| 37 | 37 | |
| 38 | 38 | } else { |
| 39 | 39 | |
| 40 | 40 | add_action('admin_head', 'lasso_fail_notice'); |
| 41 | - function lasso_fail_notice(){ |
|
| 41 | + function lasso_fail_notice() { |
|
| 42 | 42 | |
| 43 | 43 | printf('<div class="error"><p>Editus requires PHP 5.4 or higher.</p></div>'); |
| 44 | 44 | |
@@ -46,11 +46,11 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | add_filter('register_post_type_args', 'lasso_show_in_rest', 10, 2); |
| 49 | -function lasso_show_in_rest($args, $post_type){ |
|
| 49 | +function lasso_show_in_rest($args, $post_type) { |
|
| 50 | 50 | |
| 51 | - $allowed_post_types = lasso_editor_get_option( 'allowed_post_types', 'lasso_editor', array( ) ); |
|
| 52 | - $allowed_post_types = apply_filters( 'lasso_allowed_post_types', $allowed_post_types ); |
|
| 53 | - if (in_array( $post_type,$allowed_post_types)) { |
|
| 51 | + $allowed_post_types = lasso_editor_get_option('allowed_post_types', 'lasso_editor', array( )); |
|
| 52 | + $allowed_post_types = apply_filters('lasso_allowed_post_types', $allowed_post_types); |
|
| 53 | + if (in_array($post_type, $allowed_post_types)) { |
|
| 54 | 54 | $args['show_in_rest'] = true; |
| 55 | 55 | if ($post_type != 'post' && $post_type != 'page') { |
| 56 | 56 | $args['rest_base'] = $post_type; |
@@ -61,21 +61,21 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | |
| 64 | -function lasso_editor_get_option( $option, $section, $default = '' ) { |
|
| 64 | +function lasso_editor_get_option($option, $section, $default = '') { |
|
| 65 | 65 | |
| 66 | - if ( empty( $option ) ) |
|
| 66 | + if (empty($option)) |
|
| 67 | 67 | return; |
| 68 | 68 | |
| 69 | - if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
|
| 69 | + if (function_exists('is_multisite') && is_multisite()) { |
|
| 70 | 70 | |
| 71 | - $options = get_site_option( $section ); |
|
| 71 | + $options = get_site_option($section); |
|
| 72 | 72 | |
| 73 | 73 | } else { |
| 74 | 74 | |
| 75 | - $options = get_option( $section ); |
|
| 75 | + $options = get_option($section); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if ( isset( $options[$option] ) ) { |
|
| 78 | + if (isset($options[$option])) { |
|
| 79 | 79 | return $options[$option]; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -88,16 +88,16 @@ discard block |
||
| 88 | 88 | )); |
| 89 | 89 | |
| 90 | 90 | // Gutenberg |
| 91 | -if( function_exists( 'is_gutenberg_page' ) ) { |
|
| 92 | - function add_raw_to_post( $response, $post, $request ) { |
|
| 91 | +if (function_exists('is_gutenberg_page')) { |
|
| 92 | + function add_raw_to_post($response, $post, $request) { |
|
| 93 | 93 | $response_data = $response->get_data(); |
| 94 | - if ( is_array( $response_data['content'] )) { |
|
| 95 | - $response_data['content']['raw'] = $post->post_content ; |
|
| 96 | - $response->set_data( $response_data ); |
|
| 94 | + if (is_array($response_data['content'])) { |
|
| 95 | + $response_data['content']['raw'] = $post->post_content; |
|
| 96 | + $response->set_data($response_data); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | return $response; |
| 100 | 100 | } |
| 101 | - add_filter( "rest_prepare_post", 'add_raw_to_post', 10, 3 ); |
|
| 101 | + add_filter("rest_prepare_post", 'add_raw_to_post', 10, 3); |
|
| 102 | 102 | } |
| 103 | 103 | |
@@ -15,21 +15,21 @@ |
||
| 15 | 15 | * |
| 16 | 16 | * @param array $fields |
| 17 | 17 | */ |
| 18 | - public function __construct( $fields ) { |
|
| 18 | + public function __construct($fields) { |
|
| 19 | 19 | $this->fields = $fields; |
| 20 | - add_filter( 'lasso_api_params', function( $params ) { |
|
| 21 | - foreach( $this->fields as $field => $cbs ) { |
|
| 20 | + add_filter('lasso_api_params', function($params) { |
|
| 21 | + foreach ($this->fields as $field => $cbs) { |
|
| 22 | 22 | //$field = lasso_clean_string( $field ); |
| 23 | - $params[ 'process_meta_update' ][ $field ] = $cbs; |
|
| 23 | + $params['process_meta_update'][$field] = $cbs; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | return $params; |
| 27 | 27 | |
| 28 | 28 | }); |
| 29 | 29 | |
| 30 | - add_filter( 'lasso_meta_fields', function( $allowed ) { |
|
| 30 | + add_filter('lasso_meta_fields', function($allowed) { |
|
| 31 | 31 | |
| 32 | - foreach( array_keys( $this->fields ) as $field ) { |
|
| 32 | + foreach (array_keys($this->fields) as $field) { |
|
| 33 | 33 | //$field = lasso_clean_string( $field ); |
| 34 | 34 | $allowed[] = $field; |
| 35 | 35 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * Get an array of addon data for the settings modal |
| 44 | 44 | * @since 0.9.4 |
| 45 | 45 | */ |
| 46 | -function lasso_get_modal_tabs(){ |
|
| 46 | +function lasso_get_modal_tabs() { |
|
| 47 | 47 | |
| 48 | 48 | $tabs = array(); |
| 49 | 49 | |
@@ -60,34 +60,34 @@ discard block |
||
| 60 | 60 | * @uses lasso_modal_addons_content() |
| 61 | 61 | * @since 0.9.4 |
| 62 | 62 | */ |
| 63 | -function lasso_modal_addons( $type = 'tab' ){ |
|
| 63 | +function lasso_modal_addons($type = 'tab') { |
|
| 64 | 64 | |
| 65 | 65 | $tabs = lasso_get_modal_tabs(); |
| 66 | 66 | $out = ''; |
| 67 | 67 | |
| 68 | - if ( $tabs ): |
|
| 68 | + if ($tabs): |
|
| 69 | 69 | |
| 70 | - if ( 'tab' == $type ) { |
|
| 70 | + if ('tab' == $type) { |
|
| 71 | 71 | |
| 72 | 72 | $out = '<ul class="lasso--modal__tabs">'; |
| 73 | 73 | |
| 74 | 74 | $out .= '<li class="active-tab" data-addon-name="core">Editus</li>'; |
| 75 | 75 | |
| 76 | - foreach ( $tabs as $tab ) { |
|
| 76 | + foreach ($tabs as $tab) { |
|
| 77 | 77 | |
| 78 | - if ( isset( $tab ) ) { |
|
| 78 | + if (isset($tab)) { |
|
| 79 | 79 | |
| 80 | - $out .= lasso_modal_addons_content( $tab, $type ); |
|
| 80 | + $out .= lasso_modal_addons_content($tab, $type); |
|
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | $out .= '</ul>'; |
| 85 | 85 | |
| 86 | - } elseif ( 'content' == $type ) { |
|
| 87 | - foreach ( $tabs as $tab ) { |
|
| 86 | + } elseif ('content' == $type) { |
|
| 87 | + foreach ($tabs as $tab) { |
|
| 88 | 88 | |
| 89 | - if ( isset( $tab ) ) { |
|
| 90 | - $out .= lasso_modal_addons_content( $tab , $type ); |
|
| 89 | + if (isset($tab)) { |
|
| 90 | + $out .= lasso_modal_addons_content($tab, $type); |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | endif; |
| 97 | 97 | |
| 98 | - return !empty( $out ) ? $out : false; |
|
| 98 | + return !empty($out) ? $out : false; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -115,26 +115,26 @@ discard block |
||
| 115 | 115 | * @since 0.9.5 |
| 116 | 116 | * @subpackage lasso_modal_addons_content |
| 117 | 117 | */ |
| 118 | -function lasso_option_form( $name = '', $options = array() ){ |
|
| 118 | +function lasso_option_form($name = '', $options = array()) { |
|
| 119 | 119 | |
| 120 | 120 | ob_start(); |
| 121 | 121 | |
| 122 | - if ( empty( $name ) || empty( $options ) || !is_array( $options ) ) |
|
| 122 | + if (empty($name) || empty($options) || !is_array($options)) |
|
| 123 | 123 | return; |
| 124 | 124 | |
| 125 | 125 | $nonce = wp_create_nonce('lasso-process-post-meta'); |
| 126 | - $key = sprintf('_lasso_%s_settings', $name ); |
|
| 126 | + $key = sprintf('_lasso_%s_settings', $name); |
|
| 127 | 127 | |
| 128 | - $out = sprintf('<form id="lasso--post-form" class="lasso--post-form">' ); |
|
| 128 | + $out = sprintf('<form id="lasso--post-form" class="lasso--post-form">'); |
|
| 129 | 129 | |
| 130 | - $out .= lasso_option_fields( $name, $options ); |
|
| 131 | - $out .='<div class="form--bottom">'; |
|
| 132 | - $out .='<input type="submit" value="'.__( 'Save', 'lasso' ).'">'; |
|
| 133 | - $out .='<input type="hidden" name="tab_name" value="'.$key.'">'; |
|
| 134 | - $out .='<input type="hidden" name="post_id" value="'.get_the_ID().'">'; |
|
| 135 | - $out .='<input type="hidden" name="nonce" value="'.$nonce.'">'; |
|
| 136 | - $out .='<input type="hidden" name="action" value="process_meta_update">'; |
|
| 137 | - $out .='</div>'; |
|
| 130 | + $out .= lasso_option_fields($name, $options); |
|
| 131 | + $out .= '<div class="form--bottom">'; |
|
| 132 | + $out .= '<input type="submit" value="'.__('Save', 'lasso').'">'; |
|
| 133 | + $out .= '<input type="hidden" name="tab_name" value="'.$key.'">'; |
|
| 134 | + $out .= '<input type="hidden" name="post_id" value="'.get_the_ID().'">'; |
|
| 135 | + $out .= '<input type="hidden" name="nonce" value="'.$nonce.'">'; |
|
| 136 | + $out .= '<input type="hidden" name="action" value="process_meta_update">'; |
|
| 137 | + $out .= '</div>'; |
|
| 138 | 138 | |
| 139 | 139 | $out .= '</form>'; |
| 140 | 140 | |
@@ -192,20 +192,20 @@ discard block |
||
| 192 | 192 | * @since 0.9.5 |
| 193 | 193 | * @subpackage lasso_modal_addons_content |
| 194 | 194 | */ |
| 195 | -function lasso_option_fields( $name = '', $options = array() ){ |
|
| 195 | +function lasso_option_fields($name = '', $options = array()) { |
|
| 196 | 196 | |
| 197 | - $out = ''; |
|
| 197 | + $out = ''; |
|
| 198 | 198 | $before = '<div class="lasso--postsettings__option">'; |
| 199 | 199 | $after = '</div>'; |
| 200 | 200 | |
| 201 | - if ( empty( $name ) || empty( $options ) ) |
|
| 201 | + if (empty($name) || empty($options)) |
|
| 202 | 202 | return; |
| 203 | 203 | |
| 204 | - foreach ( (array) $options as $option ) { |
|
| 204 | + foreach ((array) $options as $option) { |
|
| 205 | 205 | |
| 206 | - $type = isset( $option['type'] ) ? $option['type'] : 'text'; |
|
| 206 | + $type = isset($option['type']) ? $option['type'] : 'text'; |
|
| 207 | 207 | |
| 208 | - $out .= sprintf('%s%s%s', $before, lasso_option_engine_option( $name, $option,$type ), $after ); |
|
| 208 | + $out .= sprintf('%s%s%s', $before, lasso_option_engine_option($name, $option, $type), $after); |
|
| 209 | 209 | |
| 210 | 210 | } |
| 211 | 211 | |
@@ -223,44 +223,44 @@ discard block |
||
| 223 | 223 | * @param $type string text, textarea, checkbox, color |
| 224 | 224 | * @since 5.0 |
| 225 | 225 | */ |
| 226 | -function lasso_option_engine_option( $name = '', $option = '', $type = '') { |
|
| 226 | +function lasso_option_engine_option($name = '', $option = '', $type = '') { |
|
| 227 | 227 | |
| 228 | - if ( empty( $type ) || empty( $option ) ) |
|
| 228 | + if (empty($type) || empty($option)) |
|
| 229 | 229 | return; |
| 230 | 230 | |
| 231 | - $id = isset( $option['id'] ) ? $option['id'] : false; |
|
| 231 | + $id = isset($option['id']) ? $option['id'] : false; |
|
| 232 | 232 | //$id = $id ? lasso_clean_string( $id ) : false; |
| 233 | 233 | |
| 234 | - $desc = isset( $option['desc'] ) ? $option['desc'] : false; |
|
| 234 | + $desc = isset($option['desc']) ? $option['desc'] : false; |
|
| 235 | 235 | |
| 236 | - $value = get_post_meta( get_the_id(), $option[ 'id' ], true ); |
|
| 236 | + $value = get_post_meta(get_the_id(), $option['id'], true); |
|
| 237 | 237 | |
| 238 | - switch ( $type ) { |
|
| 238 | + switch ($type) { |
|
| 239 | 239 | case 'text': |
| 240 | - $out = sprintf('<label for="lasso--post-option-%s">%s</label><input id="lasso--post-option-%s" class="editus-custom-field-text" name="%s" type="text" value="%s">',$id, esc_html( $desc ), $id, $id, $value ); |
|
| 240 | + $out = sprintf('<label for="lasso--post-option-%s">%s</label><input id="lasso--post-option-%s" class="editus-custom-field-text" name="%s" type="text" value="%s">', $id, esc_html($desc), $id, $id, $value); |
|
| 241 | 241 | break; |
| 242 | 242 | case 'textarea': |
| 243 | - $out = sprintf('<label for="lasso--post-option-%s">%s</label><textarea id="lasso--post-option-%s" name="%s">%s</textarea>',$id, esc_html( $desc ), $id, $id, $value ); |
|
| 243 | + $out = sprintf('<label for="lasso--post-option-%s">%s</label><textarea id="lasso--post-option-%s" name="%s">%s</textarea>', $id, esc_html($desc), $id, $id, $value); |
|
| 244 | 244 | break; |
| 245 | 245 | case 'imgurl': |
| 246 | - $out = sprintf('<label for="lasso--post-option-%s">%s</label><img src="%s" style="height:80px;"><input id="lasso--post-option-%s" class="editus-custom-field-text" name="%s" type="text" value="%s" style="display:none;"><div title="Replace Image" class="editus-customtab-image-control" style="float:left;"><i class="lasso-icon-image" style="font-size:20px;padding:5px;"></i></div><div title="Remove Image" class="editus-customtab-image-remove" style="float:left;"><i class="lasso-icon-bin2" style="font-size:20px;padding:5px;"></i></div>',$id, esc_html( $desc ), $value, $id, $id, $value ); |
|
| 246 | + $out = sprintf('<label for="lasso--post-option-%s">%s</label><img src="%s" style="height:80px;"><input id="lasso--post-option-%s" class="editus-custom-field-text" name="%s" type="text" value="%s" style="display:none;"><div title="Replace Image" class="editus-customtab-image-control" style="float:left;"><i class="lasso-icon-image" style="font-size:20px;padding:5px;"></i></div><div title="Remove Image" class="editus-customtab-image-remove" style="float:left;"><i class="lasso-icon-bin2" style="font-size:20px;padding:5px;"></i></div>', $id, esc_html($desc), $value, $id, $id, $value); |
|
| 247 | 247 | break; |
| 248 | 248 | case 'checkbox': |
| 249 | - $out = sprintf('<label for="lasso--post-option-%s" class="checkbox-control checkbox"><input id="lasso--post-option-%s" type="checkbox" name="%s" class="checkbox"><span class="control-indicator"></span>%s',$id, $id, $id ,esc_html( $desc ) ); |
|
| 249 | + $out = sprintf('<label for="lasso--post-option-%s" class="checkbox-control checkbox"><input id="lasso--post-option-%s" type="checkbox" name="%s" class="checkbox"><span class="control-indicator"></span>%s', $id, $id, $id, esc_html($desc)); |
|
| 250 | 250 | break; |
| 251 | 251 | case 'dropdown': |
| 252 | - $out = sprintf('<label for="lasso--post-option-%s">%s</label><select id="lasso--post-option-%s" name="%s">',$id, esc_html( $desc ), $id, $id); |
|
| 252 | + $out = sprintf('<label for="lasso--post-option-%s">%s</label><select id="lasso--post-option-%s" name="%s">', $id, esc_html($desc), $id, $id); |
|
| 253 | 253 | $options = explode(";", $option['options']); |
| 254 | 254 | foreach ($options as &$opt) { |
| 255 | 255 | $opts = explode(":", $opt); |
| 256 | 256 | if ($opts[0] == $value) { |
| 257 | - $out .= sprintf('<option value = "%s" selected>%s</option>',$opts[0], $opts[1]); |
|
| 257 | + $out .= sprintf('<option value = "%s" selected>%s</option>', $opts[0], $opts[1]); |
|
| 258 | 258 | } else { |
| 259 | - $out .= sprintf('<option value = "%s">%s</option>',$opts[0], $opts[1]); |
|
| 259 | + $out .= sprintf('<option value = "%s">%s</option>', $opts[0], $opts[1]); |
|
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - $out .='</select>'; |
|
| 263 | + $out .= '</select>'; |
|
| 264 | 264 | break; |
| 265 | 265 | } |
| 266 | 266 | |
@@ -119,8 +119,9 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | ob_start(); |
| 121 | 121 | |
| 122 | - if ( empty( $name ) || empty( $options ) || !is_array( $options ) ) |
|
| 123 | - return; |
|
| 122 | + if ( empty( $name ) || empty( $options ) || !is_array( $options ) ) { |
|
| 123 | + return; |
|
| 124 | + } |
|
| 124 | 125 | |
| 125 | 126 | $nonce = wp_create_nonce('lasso-process-post-meta'); |
| 126 | 127 | $key = sprintf('_lasso_%s_settings', $name ); |
@@ -198,8 +199,9 @@ discard block |
||
| 198 | 199 | $before = '<div class="lasso--postsettings__option">'; |
| 199 | 200 | $after = '</div>'; |
| 200 | 201 | |
| 201 | - if ( empty( $name ) || empty( $options ) ) |
|
| 202 | - return; |
|
| 202 | + if ( empty( $name ) || empty( $options ) ) { |
|
| 203 | + return; |
|
| 204 | + } |
|
| 203 | 205 | |
| 204 | 206 | foreach ( (array) $options as $option ) { |
| 205 | 207 | |
@@ -225,8 +227,9 @@ discard block |
||
| 225 | 227 | */ |
| 226 | 228 | function lasso_option_engine_option( $name = '', $option = '', $type = '') { |
| 227 | 229 | |
| 228 | - if ( empty( $type ) || empty( $option ) ) |
|
| 229 | - return; |
|
| 230 | + if ( empty( $type ) || empty( $option ) ) { |
|
| 231 | + return; |
|
| 232 | + } |
|
| 230 | 233 | |
| 231 | 234 | $id = isset( $option['id'] ) ? $option['id'] : false; |
| 232 | 235 | //$id = $id ? lasso_clean_string( $id ) : false; |