'text', // тип 'id' => 'acfyandex_data_apikey', 'desc' => __('This key is optional. For high loads or frequent failures, we recommend that you obtain the API key of this service.
Terms of Use for the Yandex Card API Service
Get API Key (click Connect API and select Static API Yandex.Cards, registration is required)','acfyandex'), // описание 'label_for' => 'acfyandex_data_apikey' ); add_settings_field( 'acfyandex_text_field', __('JavaScript API и HTTP Geocoder','acfyandex'), ['acfyandex_plugin','option_display_settings'], acfyandex_truepage, 'acfyandex_section_map', $true_field_params); $true_field_params = array( 'type' => 'select', 'id' => 'acfyandex_data_zoom', 'vals' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19), 'label_for' => 'acfyandex_data_zoom' ); add_settings_field( 'acfyandex_select_field', __('Zoom by default','acfyandex'), ['acfyandex_plugin','option_display_settings'], acfyandex_truepage, 'acfyandex_section_map', $true_field_params); } public function validate_settings($input) { foreach($input as $k => $v) { switch (trim(strtolower($k))) { case 'acfyandex_data_zoom': $v = (int) sanitize_text_field($v); if($v<0)$v=0; if($v>19)$v=19; $valid_input[$k] = $v; break; default: $valid_input[$k] = sanitize_text_field($v); break; } $valid_input[$k] = trim($v); } return $valid_input; } public function option_display_settings($args) { extract( $args ); $o = get_option( acfyandex_nameoption ); switch ( $type ) { case 'text': $o[$id] = esc_attr( stripslashes($o[$id]) ); echo ""; echo ($desc != '') ? "
$desc" : ""; break; case 'textarea': $o[$id] = esc_attr( stripslashes($o[$id]) ); echo ""; echo ($desc != '') ? "
$desc" : ""; break; case 'checkbox': $checked = ($o[$id] == 'on') ? " checked='checked'" : ''; echo ""; break; case 'select': echo ""; break; case 'radio': echo "
"; foreach($vals as $v=>$l){ $checked = ($o[$id] == $v) ? "checked='checked'" : ''; echo "
"; } echo "
"; break; } } public function startSession() { //if(current_user_can('manage_options')) if (!is_plugin_active( 'advanced-custom-fields/acf.php' ) ){ add_action('admin_notices', ['acfyandex_plugin','message_admin_error']); } if(!session_id()) {session_start();} add_action( 'admin_enqueue_scripts', ['acfyandex_plugin','acfyandex_scriptsinit']); } public function __construct() { $this->settings = array( 'version' => '1', 'url' => plugin_dir_url( __FILE__ ), 'path' => plugin_dir_path( __FILE__ ) ); add_action('acf/include_field_types', array($this, 'include_field_types')); // v5 } public function include_field_types( $version = false ) { if( ! $version ) { $version = 5; } require( dirname( __FILE__ ) . '/fields/acfyandex_common.php'); require( dirname( __FILE__ ) . '/fields/acfyandex_version' . $version . '.php'); new acfyandex_version( $this->settings ); //add_action( 'admin_enqueue_scripts', ['acfyandex_plugin','acfyandex_scriptsinit']); } public function acfyandex_scriptsinit() { $values = get_option('acfyandex_data'); $api_key = array_key_exists('acfyandex_data_apikey', $values)?$values['acfyandex_data_apikey']:''; wp_register_script('acfyandex-key',"//api-maps.yandex.ru/2.1/?apikey={$api_key}&lang=ru_RU"); wp_register_script('acfyandex-v5-client', plugin_dir_url(__FILE__) . 'assets/js/acfyandex-v5_client.js'); wp_enqueue_script( ['acfyandex-key','acfyandex-v5-client'] ); } public function group_value($atts){ $arr = []; foreach($atts as $key=>$value){ $arr_pref=explode("_",$key); $pref = $arr_pref[0]; unset($arr_pref[0]); $newkey = implode("_", $arr_pref); if(strlen(trim($newkey))>0){ if(strlen(trim($pref))>0)$arr[$pref][$newkey] = $value; else $arr['_'.$newkey] = $value; } else $arr[$pref] = $value; } return $arr; } public function tag_paramerts($arr){ $ret=""; foreach($arr as $key=>$value) if((substr($key,0,1)!=='_')&&(isset($value))) if(!is_array($value)){ if(strlen(trim(isset($value)?$value:""))>0) $ret.=(strlen(trim($ret))>0?" ":"")."{$key}='{$value}'";} else{ $subret=""; foreach($value as $subkey=>$subvalue) if((substr($subkey,0,1)!=='_')&&(strlen(trim(isset($subvalue)?$subvalue:""))>0)) $subret.=(strlen(trim($subret))>0?" ":"")."{$subkey}:{$subvalue};"; if((strlen(trim($subret))>0))$ret.=(strlen(trim($ret))>0?" ":"")."{$key}='{$subret}'"; } return $ret; } public function shortcode_yandexmap($atts){ $values_setup = get_option('acfyandex_data'); $zoom = esc_attr(array_key_exists('acfyandex_data_zoom', $values_setup)?$values_setup['acfyandex_data_zoom']:10); $point=null; if($atts['point']===null){ $subpoint = null; if($atts['_field']) $point = get_field($atts['_field']); if(strlen(trim($point))<1)$point = null; } $title=''; if(strlen(trim($atts['title']))<1)$title = get_the_title(); $memo_content = esc_html(get_the_excerpt()?get_the_excerpt():''); $memo_title = esc_html(get_the_title()?get_the_title():''); $memo_image = esc_url(get_the_post_thumbnail_url()?get_the_post_thumbnail_url():''); $memo_template = ''; if(strlen(trim($memo_title))>0)$memo_template.="

{$memo_title}

"; if(strlen(trim($memo_image))>0)$memo_template.=""; if(strlen(trim($memo_content))>0)$memo_template.=$memo_content; $atts = shortcode_atts([ 'style_width' => '100%', 'style_height' => '300px', 'point' => $point, 'zoom' => $zoom, 'title' => $title, 'memo' => $memo_content, '_field' => false, ], $atts ); if(!$atts['point']) return ''; $atts['memo']="

{$memo_title}

{$atts['memo']}"; $tag_paramerts = trim(acfyandex_plugin::tag_paramerts(acfyandex_plugin::group_value($atts))); if(strlen($tag_paramerts)>0)$tag_paramerts=" {$tag_paramerts}"; $ret="
"; //$api_key = array_key_exists('acfyandex_data_apikey', $values)?$values['acfyandex_data_apikey']:''; return $ret; } } new acfyandex_plugin;