function extrp_set_noimage() { global $extrp_settings; if (!is_admin()) { return; } if (!isset($extrp_settings['noimage']['default'])) { return; } if ('' == $extrp_settings['noimage']['default'] || false == wp_get_attachment_image_src($extrp_settings['noimage']['attachment_id'], 'full', false)) { $bail_noimage = extrp_bail_noimage(); update_option('extrp_option', $bail_noimage); } }
public function sanitize($input) { global $extrp_sanitize, $extrp_settings; $extrp_data = $extrp_sanitize->big_data(); $default = extrp_default_setting(); $new_input = array(); $id = absint($extrp_sanitize->extrp_multidimensional_search($extrp_data, array('parameter' => 'post_type'))); $post_type = array(); foreach ($extrp_data[$id]['optional'] as $type) { $type = sanitize_key($type); if (isset($input['post_type_' . $type])) { $post_type[] = $type; } } if (!array_filter($post_type)) { $post_type[] = 'post'; } $input['post_type'] = $post_type; $input['post_date'] = array(isset($input['post_date_show_date']) ? sanitize_key($input['post_date_show_date']) : '', isset($input['post_date_time_diff']) ? sanitize_key($input['post_date_time_diff']) : ''); if (isset($input['delcache'])) { global $wpdb; $caches = wp_cache_get('extrp_transient_cache_all', 'extrpcache'); if (false == $caches) { $s = "%extrp_cache_post_%"; $sql = "\n\t\t\t\t\t\t SELECT option_name\n\t\t\t\t\t\t FROM {$wpdb->options}\n\t\t\t\t\t\t WHERE option_name\n\t\t\t\t\t\t LIKE %s\n\t\t\t\t\t\t "; $sql = $wpdb->prepare($sql, $s); $caches = $wpdb->get_col($sql); wp_cache_set('extrp_transient_cache_all', $caches, 'extrpcache', 300); } if ($caches) { $del_transient = array(); foreach ($caches as $transient) { if (!delete_option($transient)) { $del_transient[] = sanitize_key($transient); } } if (false == in_array('error', $del_transient)) { $msg = __('Success to delete all cache.', 'extrp'); add_settings_error('extrp-notices', esc_attr('delete-cache'), $msg, 'updated'); } else { $msg = __('These caches still exist, try to delete again. If error still exist, check your database connection.', 'extrp'); $list = implode('</li><li>', $del_transient); $list = sprintf('<p><ul><li>%s</li></ul></p>', $list); add_settings_error('extrp-notices', esc_attr('delete-cache'), $msg . $list, 'error'); } } else { $msg = __('Cache was empty, there is no cache need to be deleted.', 'extrp'); add_settings_error('extrp-notices', esc_attr('delete-cache'), $msg, 'notice-warning'); } } if (!isset($input['thumb']) && !isset($input['post_title'])) { $msg = __('Unable to hide the post title if thumbnail not set.', 'extrp'); add_settings_error('extrp-notices', 'hide-title', $msg, 'notice-warning'); $input['post_title'] = (bool) 1; } if (isset($input['relevanssi']) && 1 == $input['relevanssi']) { if (0 == $this->with_relevanssi) { add_settings_error('extrp-notices', esc_attr('error-notice-relevanssi'), __('Unable to use Relevanssi algorithm, please activate/install Relevanssi plugin', 'extrp'), 'notice-warning'); $input['relevanssi'] = (bool) 0; } } if (isset($input['customsize_size']) && '' !== $input['customsize_size']) { if (false == $extrp_sanitize->customsize_key($input['customsize_size'])) { $msg = __('Unable to add this image size, please check your input again.', 'extrp'); $keyname = sprintf('<kbd>%s</kbd>', esc_html($input['customsize_size'])); add_settings_error('extrp-notices', 'error-notice-customsize', $msg . $keyname, 'error'); $input['customsize'] = $extrp_settings['customsize']; } else { if ('' != intval($input['customsize_width']) && '' != intval($input['customsize_height'])) { $input['customsize_crop'] = isset($input['customsize_crop']) ? (bool) 1 : (bool) 0; $customsize = array(); for ($i = 0; $i < count($input['customsize_size']); $i++) { $customsize[$i] = array('size' => sanitize_key($input['customsize_size']), 'width' => intval($input['customsize_width']), 'height' => intval($input['customsize_height']), 'crop' => wp_validate_boolean($input['customsize_crop'])); } $input['customsize'] = $customsize; } else { $msg = __('Unable to add this image size, width or height is not defined.', 'extrp'); add_settings_error('extrp-notices', 'error-notice-customsize', $msg, 'error'); $input['customsize'] = $extrp_settings['customsize']; } } } if (isset($input['highlight'])) { if ('' != $input['highlight']) { $input['hl'] = is_array($input['highlight']) ? $extrp_sanitize->highlight_name($input['highlight']['hl']) : $extrp_sanitize->highlight_name($input['highlight']); $input['hlt'] = isset($input['hl_val_' . $input['hl']]) ? sanitize_text_field($input['hl_val_' . $input['hl']]) : sanitize_key($input['hl']); if ('no' != $input['hl']) { if ('col' == $input['hl'] || 'bgcol' == $input['hl']) { $input['hlt'] = $extrp_sanitize->sanitize_hex_color($input['hlt']); } if ('css' == $input['hl']) { $input['hlt'] = sanitize_text_field($input['hlt']); } if ('class' == $input['hl']) { $input['hlt'] = sanitize_html_class($input['hlt']); } } $input['highlight'] = array('hl' => $input['hl'], 'hlt' => $input['hlt']); } else { $msg = __('Unable to set highlight, please check your input again.', 'extrp'); add_settings_error('extrp-notices', 'error-notice-highlight', $msg, 'error'); $input['highlight'] = $extrp_settings['highlight']; } } $keys = array_keys($default); if (isset($input['reset']) && 'Reset' == sanitize_text_field($input['reset'])) { $msg = __('Success to reset your data.', 'extrp'); add_settings_error('extrp-notices', esc_attr('reset-notice'), $msg, 'updated'); $attach_id = extrp_get_attach_id(esc_url_raw($input['src']), null); if (!$attach_id) { $attach_id_default = extrp_get_attach_id($extrp_sanitize->noimage_default(), null); if (!$attach_id_default) { return extrp_bail_noimage(); } } return $default; } if (isset($input['src'])) { $attach_id = extrp_get_attach_id(esc_url_raw($input['src']), null); if (!$attach_id) { $attach_id_default = extrp_get_attach_id($extrp_sanitize->noimage_default(), null); if (!$attach_id_default) { return extrp_bail_noimage(); } return $extrp_settings; } $input['noimage'] = array('attachment_id' => absint($input['attachment_id']), 'default' => $extrp_sanitize->noimage_default(), 'size' => sanitize_key($input['image_size']), 'src' => esc_url_raw($input['src']), 'crop' => isset($input['crop']) ? wp_validate_boolean($input['crop']) : false); } foreach ($keys as $k) { if (isset($input[$k])) { $new_input[$k] = $input[$k]; } else { $new_input[$k] = false; } } return $extrp_sanitize->sanitize($new_input); }