public function delete_from_theme() { foreach ($this->templates as $key => $template) { $destination = trailingslashit($this->theme_template_path) . '/' . $key; SB_PHP::delete_file($destination); } }
public function admin_style_and_script() { $page = SB_Admin_Custom::get_current_page(); if (SB_PHP::is_string_contain($page, 'sb')) { wp_enqueue_media(); } }
public function save($post_id) { if (!SB_Core::verify_nonce('sb_meta_box', 'sb_meta_box_nonce') || defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || !current_user_can('edit_post', $post_id)) { return $post_id; } foreach ($this->fields as $field) { $type = isset($field['type']) ? $field['type'] : ''; $name = isset($field['name']) ? $field['name'] : ''; if (empty($name)) { continue; } if ('checkbox' == $type) { $value = isset($_POST[$name]) ? 1 : 0; } elseif ('datetime' == $type) { $value = isset($_POST[$name]) ? SB_PHP::string_to_datetime($_POST[$name], 'Y-m-d') : ''; if (!empty($value)) { $value = strtotime($value); } } else { $value = isset($_POST[$name]) ? $_POST[$name] : ''; } $meta_value = SB_Core::sanitize($value, $type); SB_Post::update_meta($post_id, $name, $meta_value); } return $post_id; }
public static function is_sb_page() { $page = self::get_current_page(); if (SB_PHP::is_string_contain($page, 'sb')) { return true; } return false; }
public static function checkbox($args = array()) { $field_class = isset($args['field_class']) ? $args['field_class'] : ''; $field_class = SB_PHP::add_string_with_space_before($field_class, 'sb-checkbox'); $args['field_class'] = $field_class; $args['type'] = 'checkbox'; SB_Field::text($args); }
public static function edit_breadcrumb_sep() { $options = self::get_wpseo_internallinks(); $sep = isset($options['breadcrumbs-sep']) ? $options['breadcrumbs-sep'] : '/'; if (!SB_PHP::is_string_contain($sep, 'span') && !SB_PHP::is_string_contain($sep, 'class')) { $options['breadcrumbs-sep'] = '<span class="sep">' . trim($sep) . '</span>'; } update_option('wpseo_internallinks', $options); }
public function get_items($args = array()) { $result = array(); $this->fetch($args); if (is_array($this->items)) { $items = $this->items; foreach ($items as $item) { $description = $item->get_description(); $thumbnail = SB_PHP::get_first_image($description); $description = strip_tags($description); $description = wp_strip_all_tags($description); $content = $item->get_content(); if (empty($thumbnail)) { $thumbnail = SB_PHP::get_first_image($content); } $value = array('permalink' => $item->get_permalink(), 'title' => $item->get_title(), 'date' => $item->get_date(SB_Option::get_date_time_format()), 'image_url' => $thumbnail, 'description' => $description, 'content' => $content); array_push($result, $value); } } return $result; }
public static function editor($args = array()) { $name = self::get_name($args); $value = isset($args['value']) ? $args['value'] : ''; $id = isset($args['id']) ? $args['id'] : ''; if (empty($id)) { $id = $name; } $label = isset($args['label']) ? $args['label'] : ''; $container_class = isset($args['container_class']) ? $args['container_class'] : ''; $container_class = SB_PHP::add_string_with_space_before($container_class, 'sb-post-meta-editor'); echo '<div class="' . $container_class . '">'; echo '<label for="' . $id . '">' . $label . ':</label>'; $args['textarea_name'] = $name; $row = isset($args['row']) ? $args['row'] : 5; $args['textarea_rows'] = $row; wp_editor($value, $id, $args); echo '</div>'; }
public static function button($args = array()) { $text = isset($args['text']) ? $args['text'] : ''; if (empty($text)) { return; } $class = isset($args['field_class']) ? $args['field_class'] : ''; $class = SB_PHP::add_string_with_space_before($class, 'sb-button'); $description = isset($args['description']) ? $args['description'] : ''; echo '<button class="' . $class . '">' . $text . '</button>'; if (!empty($description)) { echo '<p class="description">' . $description . '</p>'; } }
public static function get_all_image_html_from_content($content) { return SB_PHP::get_all_image_html_from_string($content); }
function sb_core_captcha_reload_ajax_callback() { $len = isset($_POST['len']) ? $_POST['len'] : 4; $code = SB_PHP::random_string_number($len); SB_Core::set_captcha_session($code); $url = SB_Core::get_captcha_url(); $url = add_query_arg(array('code' => strtotime(SB_Core::get_current_datetime())), $url); echo $url; die; }
public static function get_favorite_stores($user_id) { $store_ids = self::get_meta($user_id, 'favorite_stores'); $store_ids = SB_PHP::json_string_to_array($store_ids); $store_ids = array_filter($store_ids); return $store_ids; }
public static function get_related_post($args = array()) { $related_posts = array(); $post_id = ''; $posts_per_page = 5; $post_type = 'post'; extract($args, EXTR_OVERWRITE); if (empty($post_id) && (is_single() || is_page() || is_singular())) { $post_id = get_the_ID(); } $tags = SB_Post::get_tag_ids($post_id); $defaults = array('post_type' => $post_type, 'tag__in' => $tags, 'posts_per_page' => -1); $defaults = wp_parse_args($defaults, $args); $posts = self::get($defaults); $tag_posts = $posts->posts; $cats = SB_Post::get_category_ids($post_id); $defaults = array('post_type' => $post_type, 'category__in' => $cats, 'posts_per_page' => -1); $defaults = wp_parse_args($defaults, $args); $posts = self::get($defaults); $cat_posts = $posts->posts; $a_part = SB_PHP::get_part_of(2 / 3, $posts_per_page); foreach ($tag_posts as $post) { if ($post->ID == $post_id || in_array($post, $related_posts)) { continue; } array_push($related_posts, $post); } $related_posts = array_slice($related_posts, 0, $a_part); if (count($related_posts) < $a_part) { $a_part_new = $posts_per_page - count($related_posts); } else { $a_part_new = $posts_per_page - $a_part; } $count = 0; foreach ($cat_posts as $post) { if ($post->ID == $post_id || in_array($post, $related_posts)) { continue; } array_push($related_posts, $post); $count++; if ($count >= $a_part_new) { break; } } return $related_posts; }
public static function color_picker($args) { $id = isset($args['id']) ? $args['id'] : ''; $default = isset($args['default']) ? $args['default'] : ''; $value = isset($args['value']) ? $args['value'] : ''; $field_class = isset($args['field_class']) ? $args['field_class'] : ''; $field_class = SB_PHP::add_string_with_space_before($field_class, 'sb-color-picker'); $description = isset($args['description']) ? $args['description'] : ''; $colors = isset($args['colors']) ? (array) $args['colors'] : array(); $colors = array_filter($colors); $before = isset($args['before']) ? $args['before'] : '<div id="' . esc_attr($id) . '" class="sb-color-options">'; $after = isset($args['after']) ? $args['after'] : '</div>'; $name = isset($args['name']) ? $args['name'] : ''; echo $before; if (count($colors) > 0) { foreach ($colors as $color) { $color_name = isset($color['name']) ? $name . '[' . $color['name'] . ']' : ''; $color_value = isset($color['color']) ? $color['color'] : ''; $color_default = isset($color['default']) ? $color['default'] : ''; $color_description = isset($color['description']) ? $color['description'] : ''; $args = array('before' => '<div class="color-area">', 'name' => $color_name, 'value' => $color_value, 'default' => $color_default, 'description' => $color_description); self::color_picker($args); } } else { $atts = array('data-default-color' => $default); $args['attributes'] = $atts; self::text($args); } self::the_after($before, $after); }
public static function register_taxonomy($args = array()) { $name = ''; $singular_name = ''; $hierarchical = true; $public = true; $show_ui = true; $show_admin_column = true; $show_in_nav_menus = false; $show_tagcloud = true; $post_types = array(); $slug = ''; if (is_array($args)) { extract($args, EXTR_OVERWRITE); } if (empty($singular_name)) { $singular_name = $name; } if (empty($name) || empty($slug) || taxonomy_exists($slug)) { return; } $labels = array('name' => $name, 'singular_name' => $singular_name, 'menu_name' => $name, 'all_items' => sprintf(__('All %s', 'sb-core'), $name), 'parent_item' => sprintf(__('Parent %s', 'sb-core'), $singular_name), 'parent_item_colon' => sprintf(__('Parent %s:', 'sb-core'), $singular_name), 'new_item_name' => sprintf(__('New %s Name', 'sb-core'), $singular_name), 'add_new_item' => sprintf(__('Add New %s', 'sb-core'), $singular_name), 'edit_item' => sprintf(__('Edit %s', 'sb-core'), $singular_name), 'update_item' => sprintf(__('Update %s', 'sb-core'), $singular_name), 'separate_items_with_commas' => sprintf(__('Separate %s with commas', 'sb-core'), SB_PHP::lowercase($name)), 'search_items' => sprintf(__('Search %s', 'sb-core'), $name), 'add_or_remove_items' => sprintf(__('Add or remove %s', 'sb-core'), $name), 'choose_from_most_used' => sprintf(__('Choose from the most used %s', 'sb-core'), $name), 'not_found' => __('Not Found', 'sb-core')); unset($args); $args = array('labels' => $labels, 'hierarchical' => $hierarchical, 'public' => $public, 'show_ui' => $show_ui, 'show_admin_column' => $show_admin_column, 'show_in_nav_menus' => $show_in_nav_menus, 'show_tagcloud' => $show_tagcloud, 'query_var' => true, 'rewrite' => array('slug' => $slug)); register_taxonomy($slug, $post_types, $args); }
public static function media_upload($args = array()) { $container_class = ''; extract($args, EXTR_OVERWRITE); SB_PHP::add_string_with_space_before($container_class, 'sb-media-upload'); $upload_button_class = isset($args['upload_button_class']) ? $args['upload_button_class'] : ''; $upload_button_class = SB_PHP::add_string_with_space_before($upload_button_class, 'sb-widget-button delegate'); $args['upload_button_class'] = $upload_button_class; $remove_button_class = isset($args['remove_button_class']) ? $args['remove_button_class'] : ''; $remove_button_class = SB_PHP::add_string_with_space_before($remove_button_class, 'sb-widget-button delegate'); $args['remove_button_class'] = $remove_button_class; ?> <div class="<?php echo $container_class; ?> "> <?php SB_Field::media_upload_no_preview($args); ?> </div> <?php }
public static function get_punctuation($str) { $punctuation = SB_PHP::get_last_char($str); if (!SB_PHP::is_punctuation($punctuation)) { $punctuation = ''; } return $punctuation; }
public static function login($username, $password, $remember = true) { $credentials = array(); $credentials['user_login'] = $username; $credentials['user_password'] = $password; $credentials['remember'] = $remember; $user = wp_signon($credentials, false); if (is_wp_error($user)) { if (SB_PHP::is_email_valid($username)) { $new_user = self::get_by('email', $username); if (self::compare_user_password($new_user, $password)) { $credentials['user_login'] = $new_user->user_login; $credentials['user_password'] = $password; $credentials['remember'] = $remember; $user = wp_signon($credentials, false); } } } return $user; }
public static function the_image($args = array()) { $url = self::generate_image($args); $file_name = SB_PHP::get_file_name_without_extension($url); if (!empty($url)) { $len = isset($args['len']) ? $args['len'] : 4; echo '<img class="sb-captcha-image captcha-code" data-file="' . $file_name . '" src="' . $url . '" data-len="' . $len . '">'; } }