post_title ) > 50 ) ? mb_substr( $post->post_title, 0, 49 ) . '...' : $post->post_title; $return[] = array( 'id' => $post->ID, 'label' => $title, ); } } echo json_encode( $return ); } else { $error = new \WP_Error( 'error_code', 'ERROR: Wrong credentials.' ); wp_send_json_error( $error ); } wp_die(); } ); \add_action( 'wp_ajax_wsal_settings_get_posts', function () { if ( is_user_logged_in() && current_user_can( 'manage_options' ) ) { // we will pass post IDs and titles to this array. $return = array(); $args = array( 's' => isset( $_GET['q'] ) ? \sanitize_text_field( \wp_unslash( $_GET['q'] ) ) : '', // the search query. 'post_status' => 'publish', // if you don't want drafts to be returned. 'ignore_sticky_posts' => 1, 'posts_per_page' => 50, // how much to show at once. ); // you can use WP_Query, query_posts() or get_posts() here - it doesn't matter. $search_results = new \WP_Query( $args ); if ( $search_results->have_posts() ) { while ( $search_results->have_posts() ) { $search_results->the_post(); // shorten the title a little. $title = ( mb_strlen( $search_results->post->post_title ) > 50 ) ? mb_substr( $search_results->post->post_title, 0, 49 ) . '...' : $search_results->post->post_title; if ( isset( $_GET['type'] ) && 'input' === $_GET['type'] ) { $return[] = array( 'id' => $search_results->post->ID, 'label' => $title, ); } else { $return[] = array( $search_results->post->ID, $title ); // array( Post ID, Post Title ). } } } echo json_encode( $return ); } else { $error = new \WP_Error( 'error_code', 'ERROR: Wrong credentials.' ); wp_send_json_error( $error ); } wp_die(); } ); \add_action( 'wp_ajax_wsal_settings_get_users', function () { if ( is_user_logged_in() && current_user_can( 'manage_options' ) ) { $result = array(); $query_params = array(); if ( isset( $_GET['q'] ) && ! is_null( $_GET['q'] ) ) { $query_params['search'] = '*' . \sanitize_text_field( \wp_unslash( $_GET['q'] ) ) . '*'; $query_params['search_columns'] = array( 'user_login', 'user_email' ); } if ( WP_Helper::is_multisite() ) { $query_params['blog_id'] = 0; } $users = \get_users( $query_params ); if ( MainWP_Addon::check_mainwp_plugin_active() ) { $mainwp_users = MainWP_Helper::find_users_by( $query_params['search_columns'], array( str_replace( '*', '%', $query_params['search'] ) ) ); $users = array_merge( $users, $mainwp_users ); } if ( empty( $users ) ) { return $result; } else { foreach ( $users as $user ) { $return[] = array( 'id' => $user->ID, 'label' => $user->user_login . ' (' . $user->user_email . ')', ); } } echo json_encode( $return ); } else { $error = new \WP_Error( 'error_code', 'ERROR: Wrong credentials.' ); wp_send_json_error( $error ); } wp_die(); } ); \add_action( 'wp_ajax_wsal_settings_get_roles', function () { if ( is_user_logged_in() && current_user_can( 'manage_options' ) ) { $search = ''; if ( isset( $_GET['q'] ) && ! is_null( $_GET['q'] ) ) { $search = \sanitize_text_field( \wp_unslash( $_GET['q'] ) ); } $role_names = WP_Helper::get_translated_roles(); if ( MainWP_Addon::check_mainwp_plugin_active() ) { $mainwp_roles = MainWP_Helper::get_collected_roles(); $role_names = array_merge( $role_names, $mainwp_roles ); } $return = array(); if ( empty( $role_names ) ) { return $return; } else { asort( $role_names ); foreach ( $role_names as $slug => $label ) { if ( ! empty( $search ) ) { if ( false !== \mb_strpos( $slug, $search ) || false !== \mb_strpos( $label, $search ) ) { $return[] = array( 'id' => $slug, 'label' => $label, ); } } else { $return[] = array( 'id' => $slug, 'label' => $label, );} } } echo json_encode( $return ); } else { $error = new \WP_Error( 'error_code', 'ERROR: Wrong credentials.' ); wp_send_json_error( $error ); } wp_die(); } ); \add_action( 'wp_ajax_wsal_settings_get_ips', function () { if ( is_user_logged_in() && current_user_can( 'manage_options' ) ) { $result = array(); $search = ''; if ( isset( $_GET['q'] ) && ! is_null( $_GET['q'] ) ) { $search = \sanitize_text_field( \wp_unslash( $_GET['q'] ) ); } $ips = Occurrences_Entity::get_ips_logged_search( $search ); if ( empty( $ips ) ) { return $result; } else { foreach ( $ips as $ip ) { $return[] = array( 'id' => $ip, 'label' => $ip, ); } } echo json_encode( $return ); } else { $error = new \WP_Error( 'error_code', 'ERROR: Wrong credentials.' ); wp_send_json_error( $error ); } wp_die(); } ); \add_action( 'wp_ajax_wsal_settings_get_sites', function () { if ( is_user_logged_in() && current_user_can( 'manage_options' ) ) { $result = array(); $search = ''; if ( isset( $_GET['q'] ) && ! is_null( $_GET['q'] ) ) { $search = \sanitize_text_field( \wp_unslash( $_GET['q'] ) ); } if ( WP_Helper::is_multisite() || MainWP_Addon::check_mainwp_plugin_active() ) { $sites = array(); if ( function_exists( 'get_sites' ) && class_exists( 'WP_Site_Query' ) ) { $sites = get_sites(); } if ( MainWP_Addon::check_mainwp_plugin_active() ) { $sites = array_merge( $sites, MainWP_Helper::get_all_sites_array() ); } if ( empty( $sites ) ) { return $result; } else { foreach ( $sites as $site ) { if ( property_exists( $site, 'site_name' ) ) { $blogname = $site->site_name; } else { $blogname = \get_blog_option( $site->blog_id, 'blogname' ); } if ( false !== \mb_strpos( \mb_strtolower( $blogname ), \mb_strtolower( $search ) ) ) { $result[] = array( 'id' => $site->blog_id, 'label' => $blogname, ); } } } echo json_encode( $result ); } } else { $error = new \WP_Error( 'error_code', 'ERROR: Wrong credentials.' ); wp_send_json_error( $error ); } wp_die(); } ); } /** * Builds the element * * @param array $settings - Array with settings. * @param string $option_name - Name of the option. * @param mixed $data - The data to show. * * @return void * * @since 5.0.0 */ public static function create( $settings, $option_name, $data ) { self::$item_id = null; self::$item_id_attr = null; self::$item_id_wrap = null; self::$name_attr = null; self::$placeholder_attr = null; self::$custom_class = null; self::$current_value = null; self::$option_type = null; self::$option_name = null; self::$settings = null; self::$edit_type = null; self::$validate_pattern = null; self::$max_chars = null; self::$min = null; self::$max = null; self::$step = null; self::prepare_data( $settings, $option_name, $data ); if ( empty( self::$option_type ) ) { return; } // Options Without Labels. $with_label = false; switch ( self::$option_type ) { case 'tab-title': self::tab_title(); break; case 'header': self::section_head(); break; case 'message': case 'success': case 'error': self::notice_message(); break; case 'hint': self::hint_message(); break; case 'hidden': self::hidden(); break; case 'html': self::html(); break; default: $with_label = true; break; } // Options With Label. if ( $with_label ) { /** Option Start */ self::option_head(); /** The Option */ switch ( self::$option_type ) { case 'text': self::text(); break; case 'arrayText': self::text_array(); break; case 'number': self::number(); break; case 'radio': self::radio(); break; case 'checkbox': self::checkbox(); break; case 'select-multiple': self::multiple_select(); break; case 'select2-multiple': self::multiple_select2(); break; case 'date': self::date(); break; case 'textarea': self::textarea(); break; case 'color': self::color(); break; case 'posts': self::posts(); break; case 'post': self::post(); break; case 'users': self::users(); break; case 'sites': self::sites(); break; case 'roles': self::roles(); break; case 'ips': self::ips(); break; case 'post_titles': self::post_titles(); break; case 'editor': self::editor(); break; case 'fonts': self::fonts(); break; case 'upload': self::upload(); break; case 'upload-font': self::upload_font(); break; case 'typography': self::typography(); break; case 'background': self::background(); break; case 'select': self::select(); break; case 'visual': self::visual(); break; case 'gallery': self::gallery(); break; case 'icon': self::icon(); break; default: break; } /** Option END */ if ( 'upload' !== self::$option_type ) { self::hint(); } echo ''; } } /** * HTML code * * @since 5.0.0 */ private static function html() { if ( ! empty( self::$settings['content'] ) ) { echo self::$settings['content']; } } /** * Setting Description * * @since 5.0.0 */ private static function hint() { if ( ! empty( self::$settings['hint'] ) ) { ?>
class="">
class="">
type="hidden" value=""> type="number" value="" >