get_settings(); add_filter('the_content', array($this, 'paste_ads_in_post'), 25); add_action('plugins_loaded', array($this, 'add_shortcodes')); } public function add_shortcodes() { $ads_shortcodes = array(); for ($i=1; $i <= 5; $i++) { $ads_shortcodes['pc']['ads-pc-'.$i] = $this->ads['pc']['custom']['ads-'.$i]; $ads_shortcodes['mobile']['ads-mob-'.$i] = $this->ads['mobile']['custom']['ads-'.$i]; } global $shortcode_tags; global $sc_shortcodes_array; $device = $this->get_device(); foreach ($ads_shortcodes['pc'] as $key => $value) { $sc_shortcodes_array[$key] = $device == 'pc' ? $value : ''; $shortcode_tags[$key] = array($this, 'shortcode_replace'); } foreach ($ads_shortcodes['mobile'] as $key => $value) { $sc_shortcodes_array[$key] = $device == 'mobile' ? $value : ''; $shortcode_tags[$key] = array($this, 'shortcode_replace'); } } public function shortcode_replace() { $args = func_get_args(); global $sc_shortcodes_array; return stripslashes($sc_shortcodes_array[$args[2]]); } public function paste_ads_in_post($content) { if (is_single()) { global $post; $ads_exclude = get_post_meta($post->ID, 'adsplacer_ads', true); $show_all_ads = $show_before = $show_in = $show_after = true; if ($ads_exclude != false) { if ($ads_exclude['all'] == 'yes') { $show_all_ads = false; } else { $show_before = ($ads_exclude['before'] == 'yes') ? false : true; $show_in = ($ads_exclude['in'] == 'yes') ? false : true; $show_after = ($ads_exclude['after'] == 'yes') ? false : true; } } if ($show_all_ads !== false) { $device = $this->get_device(); $pc_before = $this->ads[$device]['before'] != '' ? stripslashes($this->ads[$device]['before']) : ''; $pc_in = $this->ads[$device]['in'] != '' ? stripslashes($this->ads[$device]['in']) : ''; $pc_after = $this->ads[$device]['after'] != '' ? stripslashes($this->ads[$device]['after']) : ''; if ($pc_in != '' && $show_in !== false) { $p_array = explode('
', $content); $p_count = count($p_array); $out_content = ''; for ($i = 0; $i < $p_count; $i++) { if ($i == intval(($p_count / 2) - 1.5)) { $out_content .= $p_array[$i] . '' . $pc_in . '
'; } else { if ($i != 0) { $out_content .= ''; } $out_content .= $p_array[$i]; } } $content = $out_content; } if ($pc_before != '' && $show_before !== false) { $content = '' . $pc_before . '
' . $content; } if ($pc_after != '' && $show_after !== false) { $content = $content . '' . $pc_after . '
'; } } } return $content; } public function get_device() { if ($this->device === false) { $useragent = $_SERVER['HTTP_USER_AGENT']; if (preg_match('/android|mobile|blackberry|nokia|opera mini|cellphone|googlebot-mobile|iemobile|nintendo wii|nitro|playstation|proxinet|sonyericsson|sony|symbian|webos|windows ce|iphone|ipod|ipad|psp|vodafone|wap|xda|avantgo|xbox|kindle|maemo|htc/i', $useragent)) { $this->device = 'mobile'; return 'mobile'; } else { $this->device = 'pc'; return 'pc'; } } else { return $this->device; } } public function register_pages() { global $submenu; add_menu_page('AdsPlace\'r', 'AdsPlace\'r', 'manage_options', 'adsplacer', array($this, 'settings_html'), 'div'); add_submenu_page('adsplacer', 'AdsPlace\'r — '.__('Settings', 'adsplacer'), __('Settings', 'adsplacer'), 'manage_options', 'adsplacer', array($this, 'settings_html')); add_submenu_page('adsplacer', 'AdsPlace\'r — '.__('Instruction', 'adsplacer'), __('Instruction', 'adsplacer'), 'manage_options', 'adsplacer_support', array($this, 'support_html')); if(get_locale() == 'ru_RU') $submenu['adsplacer'][] = array('AdsPlace\'r Pro', 'manage_options', 'https://wp-r.ru/plaginy/adsplacer-pro.html'); } public function admin_enqueue_scripts($page) { wp_enqueue_style('adsplacer_font_awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css', array(), false); wp_enqueue_style('adsplacer_backend_style', ADSPLACER_PLUGIN_URL.'assets/css/admin-style.css', array(), false); if ($page == 'toplevel_page_adsplacer' || $page == 'placer_page_adsplacer_support' || $page == 'post.php') { wp_enqueue_script('adsplacer_backend_js', ADSPLACER_PLUGIN_URL.'assets/js/jquery.adsplacer.js', array('jquery', 'jquery-ui-core', 'jquery-ui-tabs', 'jquery-effects-core', 'jquery-ui-widget'), false, true); } } public function add_metabox() { add_meta_box('adsplacer_exclude_ads_for_post', 'AdsPlace\'r', array($this, 'exclude_ads'), 'post', 'side'); } public function exclude_ads() { global $post; $ads_exclude = array( 'all' => array( 'value' => 'no', 'checked' => '' ), 'before' => array( 'value' => 'no', 'checked' => '', 'disabled' => '' ), 'before' => array( 'value' => 'no', 'checked' => '', 'disabled' => '' ), 'before' => array( 'value' => 'no', 'checked' => '', 'disabled' => '' ) ); $ads = get_post_meta($post->ID, 'adsplacer_ads', true); $c = ' checked="checked"'; $d = ' disabled'; if ($ads != false) { foreach ($ads as $key => $value) { if ($key == 'all') { $ads_exclude['all']['value'] = $value; if ($value == 'yes') { $ads_exclude['all']['checked'] = $c; $ads_exclude['before']['disabled'] = $d; $ads_exclude['in']['disabled'] = $d; $ads_exclude['after']['disabled'] = $d; } else { $ads_exclude['all']['checked'] = ''; $ads_exclude['before']['disabled'] = ''; $ads_exclude['in']['disabled'] = ''; $ads_exclude['after']['disabled'] = ''; } } else { $ads_exclude[$key]['value'] = $value; if ($value == 'yes') { $ads_exclude[$key]['checked'] = $c; } else { $ads_exclude[$key]['checked'] = ''; } } } } ?> 'no', 'before' => 'no', 'in' => 'no', 'after' => 'no' ); foreach ($ads_exclude as $key => $exclude) { if (isset($_POST['adplacer_exclude_'.$key]) && $_POST['adplacer_exclude_'.$key] == 'yes') { $ads_exclude[$key] = 'yes'; } } update_post_meta($post_id, 'adsplacer_ads', $ads_exclude); } public function settings_html() { $this->save_settings(); $content = $this->get_content(); $this->render_page($content); } public function get_settings() { $this->ads = get_option('adsplacer_ads'); } public function render_page($settings) { $pc = $settings['pc']; $mobile = $settings['mobile']; ?>[ads-pc-1]',
'content' => stripslashes($ads['pc']['custom']['ads-1'])
),
'2' => array(
'title' => __('Arbitrary advertising unit', 'adsplacer') . ' #2',
'description' => __('Advertisement is shown in the arbitrary place of the site by means of a short-code', 'adsplacer') . ' [ads-pc-2]',
'content' => stripslashes($ads['pc']['custom']['ads-2'])
),
'3' => array(
'title' => __('Arbitrary advertising unit', 'adsplacer') . ' #3',
'description' => __('Advertisement is shown in the arbitrary place of the site by means of a short-code', 'adsplacer') . ' [ads-pc-3]',
'content' => stripslashes($ads['pc']['custom']['ads-3'])
),
'4' => array(
'title' => __('Arbitrary advertising unit', 'adsplacer') . ' #4',
'description' => __('Advertisement is shown in the arbitrary place of the site by means of a short-code', 'adsplacer') . ' [ads-pc-4]',
'content' => stripslashes($ads['pc']['custom']['ads-4'])
),
'5' => array(
'title' => __('Arbitrary advertising unit', 'adsplacer') . ' #5',
'description' => __('Advertisement is shown in the arbitrary place of the site by means of a short-code', 'adsplacer') . ' [ads-pc-5]',
'content' => stripslashes($ads['pc']['custom']['ads-5'])
),
)
),
'mobile' => array(
'defined' => array(
'mobileBeforeContent' => array(
'title' => __('Before content', 'adsplacer'),
'description' => __('Is shown before the main content of the article', 'adsplacer'),
'textarea_name' => 'mobile[before]',
'content' => stripslashes($ads['mobile']['before'])
),
'mobileInContent' => array(
'title' => __('In content', 'adsplacer'),
'description' => __('Is shown exactly in the middle of the article', 'adsplacer'),
'textarea_name' => 'mobile[in]',
'content' => stripslashes($ads['mobile']['in'])
),
'mobileAfterContent' => array(
'title' => __('After content', 'adsplacer'),
'description' => __('Is shown directly after the content', 'adsplacer'),
'textarea_name' => 'mobile[after]',
'content' => stripslashes($ads['mobile']['after'])
)
),
'custom' => array(
'1' => array(
'title' => __('Arbitrary advertising unit', 'adsplacer') . ' #1',
'description' => __('Advertisement is shown in the arbitrary place of the site by means of a short-code', 'adsplacer') . ' [ads-mob-1]',
'content' => stripslashes($ads['mobile']['custom']['ads-1'])
),
'2' => array(
'title' => __('Arbitrary advertising unit', 'adsplacer') . ' #2',
'description' => __('Advertisement is shown in the arbitrary place of the site by means of a short-code', 'adsplacer') . ' [ads-mob-2]',
'content' => stripslashes($ads['mobile']['custom']['ads-2'])
),
'3' => array(
'title' => __('Arbitrary advertising unit', 'adsplacer') . ' #3',
'description' => __('Advertisement is shown in the arbitrary place of the site by means of a short-code', 'adsplacer') . ' [ads-mob-3]',
'content' => stripslashes($ads['mobile']['custom']['ads-3'])
),
'4' => array(
'title' => __('Arbitrary advertising unit', 'adsplacer') . ' #4',
'description' => __('Advertisement is shown in the arbitrary place of the site by means of a short-code', 'adsplacer') . ' [ads-mob-4]',
'content' => stripslashes($ads['mobile']['custom']['ads-4'])
),
'5' => array(
'title' => __('Arbitrary advertising unit', 'adsplacer') . ' #5',
'description' => __('Advertisement is shown in the arbitrary place of the site by means of a short-code', 'adsplacer') . ' [ads-mob-5]',
'content' => stripslashes($ads['mobile']['custom']['ads-5'])
),
)
)
);
return $settings;
}
public function save_settings() {
if (isset($_POST['pc']) && isset($_POST['mobile'])) {
$pcBefore = trim($_POST['pc']['before']);
$pcIn = trim($_POST['pc']['in']);
$pcAfter = trim($_POST['pc']['after']);
$pcCustom = array(
'ads-1' => trim($_POST['pc']['ads-1']),
'ads-2' => trim($_POST['pc']['ads-2']),
'ads-3' => trim($_POST['pc']['ads-3']),
'ads-4' => trim($_POST['pc']['ads-4']),
'ads-5' => trim($_POST['pc']['ads-5'])
);
$mobileBefore = trim($_POST['mobile']['before']);
$mobileIn = trim($_POST['mobile']['in']);
$mobileAfter = trim($_POST['mobile']['after']);
$mobileCustom = array(
'ads-1' => trim($_POST['mobile']['ads-1']),
'ads-2' => trim($_POST['mobile']['ads-2']),
'ads-3' => trim($_POST['mobile']['ads-3']),
'ads-4' => trim($_POST['mobile']['ads-4']),
'ads-5' => trim($_POST['mobile']['ads-5'])
);
$insert = array(
'pc' => array(
'before' => $pcBefore,
'in' => $pcIn,
'after' => $pcAfter,
'custom' => $pcCustom
),
'mobile' => array(
'before' => $mobileBefore,
'in' => $mobileIn,
'after' => $mobileAfter,
'custom' => $mobileCustom
)
);
update_option('adsplacer_ads', $insert, true);
}
return true;
}
public function support_html() {
?>
Если не любите читать, посмотрите видео.
А вот инструкция как настроить свой плагин кеширования, чтобы он корректно работал для пользователей с разных платформ (PC и мобильных).
При помощи AdsPlace’r вы сможете показывать разные блоки рекламы посетителям своего сайта, которые зашли с PC и которые зашли с мобильного гаджета (смартфон или планшет).
Плагин AdsPlace'r автоматически вставляет ваши рекламные блоки:
На странице настроек есть 2 основные вкладки – Для PC и Для Мобильных ОС.
Каждая вкладка имеет одинаковый набор блоков для вставки кода. При этом есть панель форматирования текста в этих блоках, если вы захотите там разместить произвольный текст.
Блоки подписаны и позволяют выбрать место, где отображать рекламу.
Ниже есть возможность использовать шорткоды для вставки рекламных блоков в произвольное место статьи. Вы можете сделать сразу 5 шорткодов для PC и 5 для Мобильных ОС.
By means of the AdsPlace’r you will be able to show different units of advertisement to visitors of your site, who use PC or mobile gadget (smartphone or tablet).
The AdsPlace’r plug-in inserts your advertising units automatically:
On the setting’s page there are two main tabs – for PC and for the mobile OS.
Each tab has an identical set of the units for the code insertion. If you want to place the arbitrary text there is also the text formatting toolbar in these units.
Units are signed and allow selecting the place where to display the advertisement.
Below there is an opportunity to use the sort-codes for to insert the advertising units in arbitrary place of the article. You can create directly 5 short-codes for PC and 5 for mobile OS.