public static function on_deactivation()
 {
     global $extrp_settings, $extrp_screen_id, $extrp_screen_id_tool;
     $current_user = wp_get_current_user();
     $user_id = $current_user->ID;
     delete_user_meta($user_id, 'closedpostboxes_' . $extrp_screen_id);
     delete_user_meta($user_id, 'metaboxhidden_' . $extrp_screen_id);
     delete_user_meta($user_id, 'meta-box-order_' . $extrp_screen_id);
     delete_user_meta($user_id, 'closedpostboxes_' . $extrp_screen_id_tool);
     delete_user_meta($user_id, 'metaboxhidden_' . $extrp_screen_id_tool);
     delete_user_meta($user_id, 'meta-box-order_' . $extrp_screen_id_tool);
     self::delete_cache();
     wp_clear_scheduled_hook('extrp_delete_cache');
     $default = extrp_default_setting();
     delete_option('extrp_version');
     update_option('extrp_with_relevanssi', (bool) 0);
     $upgraded_from = get_option('extrp_version_upgraded_from');
     if ($upgraded_from) {
         delete_option('extrp_version_upgraded_from');
     }
     wp_delete_attachment(extrp_get_attach_id($extrp_settings['noimage']['default'], null), true);
 }
 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);
 }
 public function process_thumb()
 {
     global $_wp_additional_image_sizes;
     $this->img_thumb_url = '';
     if (isset($_wp_additional_image_sizes[$this->size])) {
         $this->img_width = $_wp_additional_image_sizes[$this->size]['width'];
         $this->img_height = $_wp_additional_image_sizes[$this->size]['height'];
     } else {
         $this->img_width = get_option($this->size . '_size_w');
         $this->img_height = get_option($this->size . '_size_h');
     }
     $this->thumb_url = extrp_aq_resize($this->img_src, $this->img_width, $this->img_height, $this->crop, false, true);
     $this->img_thumb_url = $this->thumb_url[0];
     $this->img_width = $this->thumb_url[1];
     $this->img_height = $this->thumb_url[2];
     if (0 == $this->attachment_id) {
         $this->attachment_id = extrp_get_attach_id($this->img_src);
     }
     $this->data_thumb = array('attachment_id' => $this->attachment_id, 'default' => $this->img_default, 'full_src' => $this->img_src, 'size' => $this->size, 'src' => $this->img_thumb_url, 'width' => $this->img_width, 'height' => $this->img_height, 'crop' => $this->crop, 'hwstring' => image_hwstring($this->img_width, $this->img_height));
     if (!array_filter($this->data_thumb)) {
         return false;
     }
     return $this->data_thumb;
 }
function extrp_upload_input($type, $txt_arr)
{
    global $extrp_settings, $extrp_sanitize;
    $full_src = esc_url_raw($extrp_settings[$type]['full_src']);
    $html = '<input type="text" value="%1$s" class="regular-text noimage" id="set-noimage" name="extrp_option[src]" readonly="readonly"><input id="attachment_id" name="extrp_option[attachment_id]" type="hidden" value="%2$s">%3$s %4$s<div class="custom-img-container">%5$s</div>';
    $img_src = esc_url_raw($extrp_settings[$type]['src']);
    if (false == extrp_get_attach_id($img_src)) {
        $attention = __('Image not exists. Please check your image from media library. You can add new one ', 'extrp');
        if ('' == $img_src) {
            $attention = __('The url default image not set up. You can add new one ', 'extrp');
        }
        $attention .= __('or push &#39;Save Changes&#39; button to get default image directly.', 'extrp');
        $attention = sprintf('<div id="message" class="error fade notice is-dismissible"><p>%1$s</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">%2$s</span></button></div>', $attention, __('Dismiss this notice.', 'extrp'));
        return sprintf($html, $full_src, absint($extrp_settings[$type]['attachment_id']), get_submit_button($txt_arr['btn_upload_txt'], 'set-noimage button thickbox', 'new_image', false), get_submit_button($txt_arr['btn_reset_txt'], 'set-noimage button reset-noimage', 'reset', false), $attention);
    }
    $attach_id = extrp_get_attach_id($full_src, null);
    if (false != $attach_id) {
        $html_img_preview = sprintf('<p><a href="%1$s" class="thickbox" title="%2$s"><img width="%3$s" height="%4$s" src="%5$s" class="extrp-shape-%6$s" data-size="%7$s" data-id="%8$s" alt="%2$s" id="upload-custom-img" data-title="%2$s"></a></p>', $full_src, get_the_title($attach_id), intval($extrp_settings[$type]['width']), intval($extrp_settings[$type]['height']), $img_src, sanitize_key($extrp_settings['shape']), sanitize_key($extrp_settings[$type]['size']), absint($attach_id));
        return sprintf($html, $full_src, absint(extrp_get_attach_id($extrp_settings['noimage']['default'], null)), get_submit_button($txt_arr['btn_upload_txt'], 'set-noimage button thickbox', 'new_image', false), get_submit_button($txt_arr['btn_reset_txt'], 'set-noimage button reset-noimage', 'reset', false), $html_img_preview);
    }
}