Plugin Directory

Changeset 2889963


Ignore:
Timestamp:
03/30/2023 08:41:07 AM (2 years ago)
Author:
vbadnow
Message:

update plugin

Location:
native-ads-adnow/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • native-ads-adnow/trunk/README.txt

    r1743357 r2889963  
    1 === Adnow Plugin ===
    2 Contributors: Adnow 
     1=== Adnow Native Widget ===
     2Contributors: Adnow
    33Tags: native ads, ad network, monetization, advertising
    44Requires at least: 3.0
    5 Tested up to: 4.8
    6 Stable tag: 1.0.4
     5Tested up to: 4.7
     6Stable tag: 1.0.2
    77License: GNU General Public License v3.0
    88License URI: http://www.gnu.org/licenses/gpl-3.0.txt
     
    1313== Description ==
    1414This plugin enables WordPress users to easily integrate Adnow's native ads widgets on their site.
    15 Generate high income on your website by showing native ads with high CTR to your visitors. 
     15Generate high income on your website by showing native ads with high CTR to your visitors.
    1616
    1717== Installation ==
     
    21212. Activate the plugin through the 'Plugins' menu in WordPress.
    2222
    23 You will find 'Adnow plugin' menu in your WordPress admin panel.
     23You will find 'Adnow Native Widget' menu in your WordPress admin panel.
    2424For basic usage, you can also have a look at the plugin homepage.
    2525
     
    2929
    3030== Frequently Asked Questions ==
    31 = How do I use AdNow Plugin? =
     31= How do I use Adnow Native Widget? =
    3232You must first contact us here at AdNow and we will get you started by setting up your account and providing you with your 'Publisher ID' and your 'Widgets ID'. After that all you need to do is download the plugin and get started.
    3333
     
    52525. Go to your profile settings (1) in the profile menu and click "WordPress plugin" (2). 
    53536. Select your website with the WordPress plugin (1). The token value will appear in the "Token" field. Select it and copy it to the Clipboard (2). 
    54 7. In the WordPress Sidebar, click "Adnow plugin" (1). Paste the token value from the Clipboard into the "Token" field (2). Click "Save Changes" 
     547. In the WordPress Sidebar, click "Adnow Native Widget" (1). Paste the token value from the Clipboard into the "Token" field (2). Click "Save Changes" 
    55558. When you save the token, the plugin configuration screen will display the information about your Adnow.com account. Antiadblock settings and statistics will also be displayed.
    56569. By default, Antiadblock is on.
    57 10. Too choose the location of the ad unit, click "Manage Places" (1). Alternatively, select "Adnow Plugin. Edit place "(2) from the Sidebar.
     5710. Too choose the location of the ad unit, click "Manage Places" (1). Alternatively, select "Adnow Native Widget. Edit place "(2) from the Sidebar.
    585811. A new window will open. You can select a page category (1) at the top of the screen and then adjust the location of the ad widget (2).
    595912. Select the widget you need from the drop-down list (1). Click "Preview" to see the widget (2) 
     
    6262
    6363== Changelog ==
    64 = 1.0.4 =
    65 * Adding new areas for advertising
    66 = 1.0.3 =
    67 * Reduction in the number of calls to the server
    6864= 1.0.2 =
    6965* Added compatibility with the plugin WP Super Cache
  • native-ads-adnow/trunk/admin/class-adnow-widget-admin.php

    r1678166 r2889963  
    11<?php
     2
     3// define('API_URL', 'http://host.docker.internal:8080/wp_aadb.php');
     4define('API_URL', 'https://wp_plug.adnow.com/wp_aadb.php');
     5
    26class Adnow_Widget_Admin {
    37    private $plugin_name;
    48    public $token;
    59    public $message_error = '';
     10    public $json;
    611    public $widgets;
    712    private $option_name = 'Adnow_Widget';
     
    1318        $this->token = false;
    1419        $this->json = '';
     20        $options_token = get_option( $this->option_name . '_key' );
     21        if(!empty($options_token)){
     22      $json = $this->apiCall($options_token);
     23            $widgets_val = json_decode($json, true);
     24            if($widgets_val["validate"] === false){
     25                $this->message_error = 'You have entered an invalid token!';
     26            }
     27            $this->token = $options_token;
     28        }
    1529    }
     30
     31    private function apiCall($token) {
     32    $params = array(
     33      'token=' . $token,
     34      'validate=1'
     35    );
     36    $url = API_URL . '?' . implode('&', $params);
     37
     38    set_error_handler(array($this, 'warning_handler'), E_WARNING);
     39    $json = file_get_contents($url);
     40    restore_error_handler();
     41
     42    return $json;
     43  }
    1644
    1745    public function enqueue_styles() {
     
    4270
    4371    public function display_options_page() {
    44         $this->get_json();
    4572        include_once 'partials/adnow-widget-admin-display.php';
    4673    }
    4774
    48     public function register_setting() {       
     75    public function register_setting() {
    4976        add_settings_section(
    5077            $this->option_name . '_general',
     
    5380            $this->plugin_name
    5481        );
    55        
     82
    5683        add_settings_section(
    5784            $this->option_name . '_head_account_key',
     
    5986            array(),
    6087            $this->plugin_name
    61         ); 
     88        );
    6289
    6390        add_settings_section(
     
    80107    }
    81108
    82     public function get_json() {
    83         $options_token = get_option( $this->option_name . '_key' );
    84         if(!empty($options_token)){
    85 
    86             $request = wp_remote_get('http://wp_plug.adnow.com/wp_aadb.php?token='.$options_token);
    87             if ( ! is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ){
    88                 $this->json = wp_remote_retrieve_body( $request );
    89             } else{
    90                 set_error_handler(array($this, "warning_handler"), E_WARNING);
    91                 $this->json = file_get_contents('http://wp_plug.adnow.com/wp_aadb.php?token='.$options_token);
    92                 restore_error_handler();
    93             }
    94 
    95             $widgets_val = json_decode($this->json, true);
    96             if(!empty($widgets_val["msg"])){
    97                 $this->message_error = $widgets_val["msg"];
    98             }
    99             $this->token = $options_token;
    100         }
    101     }
    102 
    103109    public function Adnow_Widget_general_cb() {
    104110        if($this->token !== false){
     111      $this->json = $this->apiCall($this->token);
    105112            $this->widgets = json_decode($this->json, true);
    106113            $account_id = !empty($this->widgets['account']['id']) ? $this->widgets['account']['id'] : '';
     
    118125                <?php else: ?>
    119126                    <input class="checkbox" autocomplete="off" type="hidden" name="<?php echo esc_html($this->option_name) . '_turn' ?>" id="<?php echo esc_html($this->option_name) . '_turn' ?>" value="before"><br>
    120                    
     127
    121128                <?php endif; ?>
    122129                </div>
     
    147154        if($this->token !== false and $this->message_error == ''){
    148155            $impressions = !empty($this->widgets['impressions']) ? $this->widgets['impressions'] : 0;
    149             $impressions = number_format($impressions, 0, '', ' '); 
     156            $impressions = number_format($impressions, 0, '', ' ');
    150157        } ?>
    151158        <?php if($this->token !== false  and $this->message_error == '') : ?>
     
    161168    }
    162169
    163     public function warning_handler($errno, $errstr) { 
    164         $this->message_error = 'Problem retrieving data from the server!';
     170    public function warning_handler($errno, $errstr) {
     171        $this->message_error = 'Problem retrieving data from the server! ' . $errstr;
    165172    }
    166173}
  • native-ads-adnow/trunk/admin/partials/adnow-widget-setting-display.php

    r1678166 r2889963  
    1414if(!empty($token)){
    1515    $json = '';
    16     $request = wp_remote_get('http://wp_plug.adnow.com/wp_aadb.php?token='.$token);
    17     if ( ! is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ){
    18         $json = wp_remote_retrieve_body( $request );
    19     } else{
    20         set_error_handler(array($this, "warning_handler"), E_WARNING);
    21         $json = file_get_contents('http://wp_plug.adnow.com/wp_aadb.php?token='.$token);
    22         restore_error_handler();
    23     }
    24 
     16    set_error_handler("warning_handler", E_WARNING);
     17  $json = file_get_contents(API_URL . '?token='.$token.'&validate=1');
     18   echo $json;
     19    restore_error_handler();
    2520    $widgets = json_decode($json, true);
    2621} else{
    27     $widgets["success"] = false;
     22    $widgets["validate"] = false;
    2823}
    2924
    30 function warning_handler($errno, $errstr) { 
     25function warning_handler($errno, $errstr) {
    3126    return false;
    3227}
    3328
    34 if($widgets["success"] !== false){
    35     $edit_area = new Adnow_Widget_Area; 
     29if($widgets["validate"] !== false){
     30    $edit_area = new Adnow_Widget_Area;
    3631    $url = !empty($_GET['url']) ? sanitize_text_field($_GET['url']) : home_url();
    3732}else{
  • native-ads-adnow/trunk/adnow-widget.php

    r1743357 r2889963  
    1010 *
    1111 * @link              https://adnow.com
    12  * @since             1.0.4
     12 * @since             2.0.1
    1313 * @package           adnow_widget
    1414 *
    1515 * @wordpress-plugin
    16  * Plugin Name:       Adnow Plugin
     16 * Plugin Name:       Adnow Native Widget
    1717 * Plugin URI:        https://adnow.com/wordpress-plugin
    1818 * Description:       Adding a widget to your website Adnow
    19  * Version:           1.0.4
     19 * Version:           2.0.1
    2020 * Author:            Adnow
    2121 * Author URI:        https://adnow.com
  • native-ads-adnow/trunk/includes/class-adnow-widget.php

    r1743357 r2889963  
    6767     * @since    1.0.0
    6868     */
    69     public function __construct()
    70     {
     69    public function __construct() {
     70
    7171        $this->plugin_name = 'adnow-widget';
    7272        $this->version = '1.0.2';
     73
    7374        $this->load_dependencies();
    7475        $this->set_locale();
     
    9596     * @access   private
    9697     */
    97     private function load_dependencies()
    98     {
     98    private function load_dependencies() {
    9999
    100100        /**
     
    130130       
    131131        $this->loader = new Adnow_Widget_Loader();
     132
    132133    }
    133134
     
    141142     * @access   private
    142143     */
    143     private function set_locale()
    144     {
     144    private function set_locale() {
     145
    145146        $plugin_i18n = new Adnow_Widget_i18n();
    146147        $plugin_i18n->set_domain( $this->get_plugin_name() );
    147148
    148149        $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
     150
    149151    }
    150152
     
    156158     * @access   private
    157159     */
    158     private function define_admin_hooks()
    159     {
     160    private function define_admin_hooks() {
     161
    160162        $plugin_admin = new Adnow_Widget_Admin( $this->get_plugin_name(), $this->get_version() );
    161163
    162164        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
    163165        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
    164 
     166       
    165167        $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_options_page' );
    166168        $this->loader->add_action( 'admin_menu' , $plugin_admin, 'make_menu' );
     
    177179     * @access   private
    178180     */
    179     private function define_public_hooks()
    180     {
     181    private function define_public_hooks() {
     182
    181183        $plugin_public = new Adnow_Widget_Public( $this->get_plugin_name(), $this->get_version() );
    182184
     
    191193     * @since    1.0.0
    192194     */
    193     public function run()
    194     {
     195    public function run() {
    195196        $this->loader->run();
    196197    }
    197198
    198     public function add_areas()
    199     {
     199    public function add_areas() {
    200200        $plugin_area = new Adnow_Widget_Add_Area;
    201201        $this->loader->add_action( 'admin_bar_menu', $plugin_area, 'modify_admin_bar', 999 );
     
    208208        $this->loader->add_filter('the_content',  $plugin_area, 'content_before_area');
    209209        $this->loader->add_filter('the_excerpt',  $plugin_area, 'excerpt_after_area');
    210         $this->loader->add_filter('widget_text_content',  $plugin_area, 'widget_text_content_area');
    211         $this->loader->add_filter('widget_custom_html_content',  $plugin_area, 'widget_custom_html_content_area');
    212         $this->loader->add_action( 'get_footer', $plugin_area, 'get_footer_area' );
    213         $this->loader->add_action( 'wp_footer', $plugin_area, 'wp_footer_area' );
    214 
     210        //$this->loader->add_filter('get_the_archive_title',  $plugin_area, 'get_the_archive_title_area');
     211        //$this->loader->add_action( 'loop_start', $plugin_area, 'loop_start_area' );
     212        //$this->loader->add_action( 'loop_end', $plugin_area, 'loop_end_area' );
     213        //$this->loader->add_action( 'wp_footer', $plugin_area, 'wp_footer_area' );
    215214        $plugin_area->empty_povt();
    216215        $this->loader->add_action( 'wp_footer', $plugin_area, 'add_obhod' );
    217216    }
    218217
     218
    219219    /**
    220220     * The name of the plugin used to uniquely identify it within the context of
     
    224224     * @return    string    The name of the plugin.
    225225     */
    226     public function get_plugin_name()
    227     {
     226    public function get_plugin_name() {
    228227        return $this->plugin_name;
    229228    }
     
    235234     * @return    Adnow_Widget_Loader    Orchestrates the hooks of the plugin.
    236235     */
    237     public function get_loader()
    238     {
     236    public function get_loader() {
    239237        return $this->loader;
    240238    }
     
    246244     * @return    string    The version number of the plugin.
    247245     */
    248     public function get_version()
    249     {
     246    public function get_version() {
    250247        return $this->version;
    251248    }
  • native-ads-adnow/trunk/public/class-adnow-widget-add-area.php

    r1743357 r2889963  
    11<?php
    22class Adnow_Widget_Add_Area {
    3 
    43    public $page_plugin;
    5 
    6     public $widgets;
    7 
     4    public $widgets = array();
    85    public $aabd;
    9 
    106    public $select_widgets;
    11 
    127    public $page_type_all;
    13 
    148    public $page_area_all;
    15 
    169    public $request_uri;
    17 
    1810    public $operation_all;
    19 
    2011    private $option_name = 'Adnow_Widget';
    2112
    22     public function __construct()
    23     {
     13
     14    public function __construct(){
    2415        global $wpdb;
    25 
    2616        $this->page_plugin = $this->getPluginStatus();
    27 
    28         $this->widgets = array();
    29 
    30         $this->select_widgets = array();
     17    $this->loadWidgets();
    3118
    3219        $this->operation_all = array('remove', 'close', 'preview', 'save');
    33 
    3420        $this->page_type_all = array('post', 'page', 'main', 'category', 'archive', 'search');
    35 
    36         $this->page_area_all = array(
    37             'wp_head',
    38             'wp_footer',
    39             'get_footer',
    40             'loop_start',
    41             'loop_end',
    42             'comment_form_before',
    43             'comment_form_after',
    44             'dynamic_sidebar_before',
    45             'dynamic_sidebar_after',
    46             'content_after',
    47             'content_before',
    48             'the_excerpt',
    49             'widget_text_content',
    50             'widget_title',
    51             'widget_custom_html_content'
    52         );
    53        
     21        $this->page_area_all = array('wp_head','wp_footer','loop_start','loop_end','comment_form_before','comment_form_after','dynamic_sidebar_before','dynamic_sidebar_after','content_after','content_before','the_excerpt');
     22
    5423        $request = $_SERVER["REQUEST_URI"];
    55 
    56         if (! empty($request)) {
     24        if(!empty($request)){
    5725            $this->request_uri = esc_url($request);
    58         } else {
     26        }else{
    5927            $this->request_uri = '/';
    6028        }
     
    6230        $post_operation = !empty($_POST['operation']) ? sanitize_text_field($_POST['operation']) : false;
    6331
    64         if (! empty($post_operation) && in_array($post_operation, $this->operation_all)) {
    65 
    66             if (! empty($_POST['widget_id']) && ! empty($_POST['action_area']) && ! empty($_POST['type_post'])) {
     32        if(!empty($post_operation) and in_array($post_operation, $this->operation_all)){
     33            if(!empty($_POST['widget_id']) and !empty($_POST['action_area']) and !empty($_POST['type_post'])){
    6734                $id_area_post = true;
    6835                $post_widget_id = intval($_POST['widget_id']);
    69 
    70                 if (! $post_widget_id) {
     36                if(!$post_widget_id){
    7137                    $id_area_post = false;
    7238                }
    73 
    7439                $post_action_area = sanitize_text_field($_POST['action_area']);
    75 
    76                 if (! in_array($post_action_area, $this->page_area_all)) {
     40                if(!in_array($post_action_area, $this->page_area_all)){
    7741                    $id_area_post = false;
    7842                }
    79 
    8043                $post_type_post =sanitize_text_field($_POST['type_post']);
    81 
    82                 if (! in_array($post_type_post, $this->page_type_all)) {
     44                if(!in_array($post_type_post, $this->page_type_all)){
    8345                    $id_area_post = false;
    8446                }
    85 
    86             } else {
     47            }else{
    8748                $id_area_post = false;
    8849            }
     
    9354        switch ($post_operation) {
    9455            case 'remove':
    95                 if (! empty($id_area_post)) {
     56                if(!empty($id_area_post)){
    9657                    $this->remove_ad($post_action_area, $post_type_post, $post_widget_id);
    9758                }
     
    9960
    10061            case 'close':
    101                 if (! empty($id_area_post)) {
     62                if(!empty($id_area_post)){
    10263                    $this->remove_ad($post_action_area, $post_type_post, $post_widget_id, '-preview-adnow');
    10364                }
     
    10566
    10667            case 'preview':
    107                 if (! empty($id_area_post)) {
    108                     $this->add_widget_array($post_widget_id, $post_action_area, $post_type_post);
     68                if(!empty($id_area_post)){
     69                    $id_widget = $this->add_widget_array($post_widget_id, $post_action_area, $post_type_post);
    10970                }
    11071            break;
     
    11273            case 'save':
    11374                $previews = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s", '%-preview-adnow%'));
    114 
    11575                foreach ($previews as $key => $double) {
    116                     $wpdb->query( $wpdb->prepare("UPDATE $wpdb->options SET option_name = REPLACE (option_name, '-preview-adnow', '') WHERE option_name = %s", sanitize_text_field($double)));
     76                    $updates = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->options SET option_name = REPLACE (option_name, '-preview-adnow', '') WHERE option_name = %s", sanitize_text_field($double)));
    11777                }
    118 
    11978                $plugin_status = $this->getPluginStatus();
    120 
    121                 if (! empty($plugin_status)) {
    122                     $wpdb->delete($wpdb->options, array( 'option_name' => 'edit_area'));
     79                if(!empty($plugin_status)){
     80                    $del = $wpdb->delete($wpdb->options, array( 'option_name' => 'edit_area'));
    12381                }
    12482            break;
     
    12684    }
    12785
    128     private function getPluginStatus()
    129     {
     86    private function getPluginStatus(){
    13087        global $wpdb;
    131 
    13288        $edit_area = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", 'edit_area'));
    133 
    134         return (! empty($edit_area)) ? true : false;
    135     }
    136 
    137     private function addHeadPanel()
    138     {
    139         global $wpdb;
    140 
    141         $type_post = $this->getTypePage();
    142         $nal_ad = $wpdb->get_row($wpdb->prepare("SELECT count(*) as cnt FROM $wpdb->options WHERE option_value LIKE %s AND option_name = %s", '%' . $type_post . '-%', 'obhod'));
    143 
    144         if ($this->getPluginStatus() === false && $nal_ad->cnt == 0) {
    145             $this->widgets = array();
    146         } else {
    147             $token = get_option( $this->option_name . '_key' );
    148             $request = wp_remote_get('http://wp_plug.adnow.com/wp_aadb.php?token=' . $token);
    149 
    150             if ( ! is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) {
    151                 $json = wp_remote_retrieve_body( $request );
    152             } else {
    153                 set_error_handler( array($this, "warning_handler"), E_WARNING );
    154 
    155                 $json = file_get_contents('http://wp_plug.adnow.com/wp_aadb.php?token=' . $token);
    156 
    157                 restore_error_handler();
    158             }
    159 
    160             if (! empty($json)) {
    161                 $widgets = json_decode($json, true);
    162 
    163                 if (! empty($widgets['widget'])) {
    164                     $this->widgets = $widgets['widget'];
    165                     $this->aabd = $widgets['aadb'];
    166 
    167                     if (is_array($this->widgets)) {
    168 
    169                         foreach ($this->widgets as $key => $value) {
    170                             $this->select_widgets[$key] = $value['title'];
    171                         }
    172                     }
    173                 } else {
    174                     $this->widgets = array();
    175                 }
    176             }
    177         }
    178        
     89        if(!empty($edit_area)){
     90            return true;
     91        }else{
     92            return false;
     93        }
     94    }
     95
     96    private function loadWidgets() {
     97    $token = get_option( $this->option_name . '_key' );
     98    set_error_handler(array($this, "warning_handler"), E_WARNING);
     99    $json = file_get_contents(API_URL . '?token=' . $token);
     100    restore_error_handler();
     101    if(!empty($json)){
     102      $widgets = json_decode($json, true);
     103      if(!empty($widgets['widget'])){
     104        $this->widgets = $widgets['widget'];
     105        $this->aabd = $widgets['aadb'];
     106        if(is_array($this->widgets)){
     107          foreach ($this->widgets as $key => $value) {
     108            $this->select_widgets[$key] = $value['title'];
     109          }
     110        }
     111      }else{
     112        $this->widgets = array();
     113      }
     114    }
     115    }
     116
     117    private function addHeadPanel(){
    179118        $headpanel = '';
    180 
    181         if ($this->is_user_role('administrator') && $this->getPluginStatus() === true) {
    182 
     119        if($this->is_user_role('administrator')  and $this->getPluginStatus() === true ){
    183120            $headpanel .= '<div_adnblock class="header_fix_top head_panel">
    184121                <div_adnblock class="container_top">
     
    189126                                <div_adnblock class="adn_pages">
    190127                                    <div_adnblock class="adn_name">Site Pages</div_adnblock>';
    191 
    192128                                    foreach ($this->page_type_all as $type) {
    193129                                        $headpanel .= $this->get_home_page($type);
    194130                                    }
    195 
    196131            $headpanel .= '</div_adnblock>
    197132                            </div_adnblock>
     
    203138            </div_adnblock>';
    204139        }
    205 
    206140        return $headpanel;
    207141    }
    208142
    209     private function getRecheck($action_area)
    210     {
     143    private function getRecheck($action_area){
    211144        global $wpdb;
    212 
    213145        $type_post = $this->getTypePage();
    214 
    215         $count_add_page = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $action_area . '_add_' . $type_post));
    216 
    217         if (! isset($count_add_page)) {
    218             $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, %s )", $action_area . '_add_' . $type_post, 'yes', 'no' ) );
    219         }
    220 
     146        $count_add_page = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $action_area.'_add_'.$type_post));
     147
     148        if(!isset($count_add_page)){
     149            $inc = $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, %s )", $action_area.'_add_'.$type_post, 'yes', 'no' ) );
     150        }
    221151        return $count_add_page;
    222152    }
    223153
    224     private function getCode($action_area, $size='big')
    225     {
     154    private function getCode($action_area, $size='big'){
    226155        global $wpdb;
    227 
    228156        $adnblock = '';
    229 
    230157        $type_post = $this->getTypePage();
    231 
    232         $vision = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $action_area . '-' . $type_post));
    233 
    234         $vision_preview = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $action_area . '-' . $type_post . '-preview-adnow'));
    235 
    236         if (! empty($vision)) {
     158        $vision = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $action_area.'-'.$type_post));
     159        $vision_preview = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $action_area.'-'.$type_post.'-preview-adnow'));
     160        if(!empty($vision)){
    237161            $vision_arr = esc_html($vision->option_value);
    238 
    239             if (! empty($this->widgets[$vision_arr])) {
     162            if(!empty($this->widgets[$vision_arr])){
    240163
    241164                $adnblock = '
    242                 <adnblock class="top_index_block_adnow" id="' . $action_area . '">
    243                     <form id="form_' . $action_area . '" method="post" action="' . $this->request_uri . '#' . $action_area . '">';
    244 
    245                     if ($this->is_user_role('administrator') && $this->getPluginStatus() === true) {
    246                         $adnblock .= '<input name="widget_id" type="hidden" value="' . $vision_arr . '">
    247                         <input name="action_area" type="hidden" value="' . $action_area . '">
    248                         <input name="type_post" type="hidden" value="' . $type_post . '">
     165                <adnblock class="top_index_block_adnow" id="'.$action_area.'">
     166                    <form id="form_'.$action_area.'" method="post" action="'.$this->request_uri.'#'.$action_area.'">';
     167                    if($this->is_user_role('administrator')  and $this->getPluginStatus() === true ){
     168                        $adnblock .= '<input name="widget_id" type="hidden" value="'.$vision_arr.'">
     169                        <input name="action_area" type="hidden" value="'.$action_area.'">
     170                        <input name="type_post" type="hidden" value="'.$type_post.'">
    249171                        <input name="operation" type="hidden" value="remove">
    250                             <button_adnblock onclick="document.getElementById(\'form_' . $action_area . '\').submit()" class="add_widget_plus_content">
     172                            <button_adnblock onclick="document.getElementById(\'form_'.$action_area.'\').submit()" class="add_widget_plus_content">
    251173                                <span_adnblock class="remove_widget">Remove widgets</span_adnblock>
    252                                 <span_adnblock class="id_title_widget"><strong>' . esc_html($this->select_widgets[$vision_arr]) . '</strong> (ID:' . $vision_arr . ')</span_adnblock>
    253                             </button_adnblock>';
     174                                <span_adnblock class="id_title_widget"><strong>'.esc_html($this->select_widgets[$vision_arr]).'</strong> (ID:'.$vision_arr.')</span_adnblock>
     175                            </button_adnblock>
     176                        ';
    254177                    }
    255 
    256178                    $adnblock .= '
    257                         <div class="prev" data-widget="' . $vision_arr . '">' . base64_decode($this->widgets[$vision_arr]['code']) . '</div>
     179                        <div class="prev" data-widget="'.$vision_arr.'">'.base64_decode($this->widgets[$vision_arr]['code']).'</div>
    258180                    </form>
    259181                </adnblock>';
    260182            }
    261         } elseif (! empty($vision_preview)) {
     183        } elseif(!empty($vision_preview)){
    262184            $vision_arr = esc_html($vision_preview->option_value);
    263 
    264             if (! empty($this->widgets[$vision_arr])) {
    265 
    266                 if ($this->is_user_role('administrator') && $this->getPluginStatus() === true) {
     185            if(!empty($this->widgets[$vision_arr])){
     186                if($this->is_user_role('administrator')  and $this->getPluginStatus() === true ){
    267187                $adnblock = '
    268                 <adnblock class="top_index_block_adnow" id="' . $action_area . '">
    269                     <form id="form_' . $action_area . '" method="post" action="' . $this->request_uri . '#' . $action_area . '">';
    270                         $adnblock .= '<input name="widget_id" type="hidden" value="' . $vision_arr . '">
    271                         <input name="action_area" type="hidden" value="' . $action_area . '">
    272                         <input name="type_post" type="hidden" value="' . $type_post . '">
     188                <adnblock class="top_index_block_adnow" id="'.$action_area.'">
     189                    <form id="form_'.$action_area.'" method="post" action="'.$this->request_uri.'#'.$action_area.'">';
     190                        $adnblock .= '<input name="widget_id" type="hidden" value="'.$vision_arr.'">
     191                        <input name="action_area" type="hidden" value="'.$action_area.'">
     192                        <input name="type_post" type="hidden" value="'.$type_post.'">
    273193                        <input name="operation" type="hidden" value="close">
    274                             <button_adnblock onclick="document.getElementById(\'form_' . $action_area . '\').submit()" class="add_widget_plus_content">
     194                            <button_adnblock onclick="document.getElementById(\'form_'.$action_area.'\').submit()" class="add_widget_plus_content">
    275195                                <span_adnblock class="remove_widget close_prev">Close view widget</span_adnblock>
    276                                 <span_adnblock class="id_title_widget"><strong>' . esc_html($this->select_widgets[$vision_arr]) . '</strong> (ID:' . $vision_arr . ')</span_adnblock>
     196                                <span_adnblock class="id_title_widget"><strong>'.esc_html($this->select_widgets[$vision_arr]).'</strong> (ID:'.$vision_arr.')</span_adnblock>
    277197                            </button_adnblock>
    278198                        ';
    279199                    $adnblock .= '
    280                         <div class="prev view_prev" data-widget="' . $vision_arr . '">' . base64_decode($this->widgets[$vision_arr]['code']) . '</div>
     200                        <div class="prev view_prev" data-widget="'.$vision_arr.'">'.base64_decode($this->widgets[$vision_arr]['code']).'</div>
    281201                    </form>
    282202                </adnblock>';
    283203                }
    284204            }
    285         } else {
    286             if ($this->is_user_role('administrator')  and $this->getPluginStatus() === true) {
     205        } else{
     206            if($this->is_user_role('administrator')  and $this->getPluginStatus() === true ){
    287207                $select_in = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", 'obhod'));
    288208
    289                 $ids = ! empty($select_in->option_value) ? explode(",", $select_in->option_value) : array();
     209                $ids_all = array();
     210                $ids = !empty($select_in->option_value) ? explode(",", $select_in->option_value) : array();
    290211                $ids = array_diff($ids, array(''));
    291212
    292213                $adnblock = '
    293                 <adnblock class="top_index_block_adnow"  id="' . $action_area . '">
    294                     <form id="form_' . $action_area . '"  method="post" action="' . $this->request_uri . '#' . $action_area . '">
    295                         <div_adnblock class="adnow_widget_block adn_' . $size . '">
     214                <adnblock class="top_index_block_adnow"  id="'.$action_area.'">
     215                    <form id="form_'.$action_area.'"  method="post" action="'.$this->request_uri.'#'.$action_area.'">
     216                        <div_adnblock class="adnow_widget_block adn_'.$size.'">
    296217                            <div_adnblock class="adn_name">Place widgets here</div_adnblock>
    297218                            <div_adnblock class="adn_form">
    298219                                <select name="widget_id" onfocus="this.parentNode.parentNode.classList.add(\'focused\');" onblur="this.parentNode.parentNode.classList.remove(\'focused\');"><option></option>';
    299 
    300                                 foreach ($this->select_widgets as $key => $value) {
    301 
    302                                     if (! in_array($type_post . '-' . $key, $ids)) {
    303                                         $adnblock .= '<option value="' . $key . '">' . $value . '</option>';
    304                                     }
    305                                 }
    306 
    307                                 $adnblock .= '
     220                                    foreach ($this->select_widgets as $key => $value) {
     221                                        if(!in_array($type_post.'-'.$key, $ids)){
     222                                            $adnblock .= '<option value="'.$key.'">'.$value.'</option>';
     223                                        }
     224                                    }
     225                                    $adnblock .= '
    308226                                </select>
    309                                 <input name="action_area" type="hidden" value="' . $action_area . '">
    310                                 <input name="type_post" type="hidden" value="' . $type_post . '">
     227                                <input name="action_area" type="hidden" value="'.$action_area.'">
     228                                <input name="type_post" type="hidden" value="'.$type_post.'">
    311229                                <input name="operation" type="hidden" value="preview">
    312                                 <button_adnblock onclick="document.getElementById(\'form_' . $action_area . '\').submit()" class="adn_submit add_widget_plus_content">Preview</button_adnblock>
     230                                <button_adnblock onclick="document.getElementById(\'form_'.$action_area.'\').submit()" class="adn_submit add_widget_plus_content">Preview</button_adnblock>
    313231                            </div_adnblock>
    314232                        </div_adnblock>
     
    317235            }
    318236        }
    319 
    320237        return $adnblock;
    321238    }
    322239
    323     private function getTypePage()
    324     {
    325         if (is_front_page()) {
     240    private function getTypePage(){
     241        if(is_front_page()){
    326242            $type_post = 'main';
    327         } elseif (is_search()) {
     243        } elseif(is_search()){
    328244            $type_post = 'search';
    329         } elseif (is_page()) {
     245        } elseif(is_page()){
    330246            $type_post = 'page';
    331         } elseif (is_single()) {
     247        } elseif(is_single()){
    332248            $type_post = 'post';
    333         } elseif (is_category()) {
     249        } elseif(is_category()){
    334250            $type_post = 'category';
    335         } elseif (is_archive()) {
     251        } elseif(is_archive()){
    336252            $type_post = 'archive';
    337         } else {
     253        } else{
    338254            $type_post = 'other';
    339255        }
    340 
    341         return $type_post;
    342     }   
    343 
    344     private function get_home_page($param)
    345     {
     256         return $type_post;
     257    }
     258
     259    private function get_home_page($param){
    346260        global $wpdb;
    347 
    348         global $cache_page_secret;
    349 
    350261        $type_post_active = $this->getTypePage();
    351262        $type_page = $param;
     
    353264
    354265        $home_page = home_url();
    355 
    356         if (! empty($param)) {
    357 
     266        if(!empty($param)){
    358267            switch ($param) {
    359268                case 'page':
    360                     $post_guid = $wpdb->get_col($wpdb->prepare("SELECT id FROM $wpdb->posts WHERE post_status = %s AND post_type = %s ORDER BY id DESC LIMIT 1", 'publish', 'page')); 
    361                     $home_page = !empty($post_guid[0]) ? get_site_url() . '/?p=' . $post_guid[0] : get_site_url() . '/';
     269                    $post_guid = $wpdb->get_col($wpdb->prepare("SELECT id FROM $wpdb->posts WHERE post_status = %s AND post_type = %s ORDER BY id DESC LIMIT 1", 'publish', 'page'));
     270                    $home_page = !empty($post_guid[0]) ? get_site_url().'/?p='.$post_guid[0] : get_site_url().'/';
    362271                break;
    363272
    364273                case 'post':
    365                     $post_guid = $wpdb->get_col($wpdb->prepare("SELECT id FROM $wpdb->posts WHERE post_status = %s AND post_type = %s ORDER BY id DESC  LIMIT 1", 'publish', 'post')); 
    366                     $home_page = !empty($post_guid[0]) ? get_site_url() . '/?p=' . $post_guid[0] : get_site_url() . '/';
     274                    $post_guid = $wpdb->get_col($wpdb->prepare("SELECT id FROM $wpdb->posts WHERE post_status = %s AND post_type = %s ORDER BY id DESC  LIMIT 1", 'publish', 'post'));
     275                    $home_page = !empty($post_guid[0]) ? get_site_url().'/?p='.$post_guid[0] : get_site_url().'/';
    367276                break;
    368277
    369278                case 'attachment':
    370                     $post_guid = $wpdb->get_col($wpdb->prepare("SELECT id FROM $wpdb->posts WHERE post_status = %s AND post_type = %s ORDER BY id DESC  LIMIT 1", 'publish', 'attachment')); 
    371                     $home_page = !empty($post_guid[0]) ? get_site_url() . '/?p=' . $post_guid[0] : get_site_url() . '/';
     279                    $post_guid = $wpdb->get_col($wpdb->prepare("SELECT id FROM $wpdb->posts WHERE post_status = %s AND post_type = %s ORDER BY id DESC  LIMIT 1", 'publish', 'attachment'));
     280                    $home_page = !empty($post_guid[0]) ? get_site_url().'/?p='.$post_guid[0] : get_site_url().'/';
    372281                break;
    373282
     
    388297
    389298                case 'search':
    390                     $home_page = home_url() . '/?s=search';
     299                    $home_page = home_url().'/?s=+';
    391300                break;
    392301            }
    393302        }
    394303
    395         if (! empty($cache_page_secret)) {
     304        global $cache_page_secret;
     305        if(!empty($cache_page_secret)){
    396306            $home_page = add_query_arg( 'donotcachepage', $cache_page_secret,  $home_page );
    397307        }
    398308
    399         return '<a class="adn_button ' . $adv_active . '" href="' . esc_url($home_page) . '">' . ucfirst($type_page) . '</a>';
     309        return '<a class="adn_button '.$adv_active.'" href="'.esc_url($home_page).'">'.ucfirst($type_page).'</a>';
    400310    }
    401311
    402     private function add_widget_array($id_widget, $action_area, $type_post)
    403     {
     312    private function add_widget_array($id_widget, $action_area, $type_post){
    404313        global $wpdb;
    405 
    406         $backup = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM $wpdb->options WHERE option_name = %s", $action_area . '-' . $type_post . '-preview-adnow'));
    407 
    408         if (count($backup) == 0) {
    409             $inc = $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, %s )", $action_area . '-' . $type_post . '-preview-adnow', $id_widget, 'no' ) );
    410            
    411             $this->obhod($type_post . '-' . $id_widget, 'add');
    412         }
    413 
     314        $backup = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM $wpdb->options WHERE option_name = %s", $action_area.'-'.$type_post.'-preview-adnow'));
     315        if(count($backup)==0){
     316            $inc = $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, %s )", $action_area.'-'.$type_post.'-preview-adnow', $id_widget, 'no' ) );
     317
     318            $this->obhod($type_post.'-'.$id_widget, 'add');
     319        }
    414320        return $inc;
     321
    415322    }
    416323
    417     private function obhod($id_widget, $action)
    418     {
     324    private function obhod($id_widget, $action){
    419325        global $wpdb;
    420 
    421326        $obhod = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM $wpdb->options WHERE option_name = %s", 'obhod'));
    422 
    423         if (count($obhod) == 0) {
    424             $wpdb->query($wpdb->prepare("INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, %s )", 'obhod', '', 'no'));
    425         }
    426 
     327        if(count($obhod)==0){
     328            $add_ob = $wpdb->query($wpdb->prepare("INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, %s )", 'obhod', '', 'no'));
     329        }
    427330        switch ($action) {
    428331            case 'add':
    429             $wpdb->query($wpdb->prepare("UPDATE $wpdb->options SET option_value = CONCAT(option_value, %s) WHERE option_name='obhod'", $id_widget . ','));
     332            $wpdb->query($wpdb->prepare("UPDATE $wpdb->options SET option_value = CONCAT(option_value, %s) WHERE option_name='obhod'", $id_widget.','));
    430333            break;
    431334
    432335            case 'remove':
    433             $wpdb->query($wpdb->prepare("UPDATE $wpdb->options SET option_value = REPLACE(option_value, %s, '')  WHERE option_name='obhod'", $id_widget . ','));
     336            $wpdb->query($wpdb->prepare("UPDATE $wpdb->options SET option_value = REPLACE(option_value, %s, '')  WHERE option_name='obhod'", $id_widget.','));
    434337            break;
    435338        }
    436339    }
    437340
    438     private function remove_ad($action_area, $type_post, $id_widget, $preview = '')
    439     {
     341    private function remove_ad($action_area, $type_post, $id_widget, $preview=''){
    440342        global $wpdb;
    441343
    442         $nal = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM $wpdb->options WHERE option_name = %s", $action_area . '-' . $type_post . $preview));
    443 
    444         if (! empty($nal)) {
    445             $wpdb->delete($wpdb->options, array( 'option_name' => $action_area . '-' . $type_post . $preview));
    446             $this->obhod($type_post . '-' . $id_widget, 'remove');
     344        $nal = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM $wpdb->options WHERE option_name = %s", $action_area.'-'.$type_post.$preview));
     345
     346        if(!empty($nal)){
     347            $del = $wpdb->delete($wpdb->options, array( 'option_name' => $action_area.'-'.$type_post.$preview));
     348            $this->obhod($type_post.'-'.$id_widget, 'remove');
    447349        }
    448350    }
    449351
    450352
    451     public function wp_head_area()
    452     {
     353    public function wp_head_area() {
    453354        echo $this->addHeadPanel();
    454355    }
    455356
    456     public function wp_footer_area()
    457     {
     357    public function wp_footer_area() {
    458358        echo $this->getCode('wp_footer');
    459359    }
    460360
    461     public function get_footer_area()
    462     {
    463         echo $this->getCode('get_footer');
    464     }
    465 
    466     public function loop_start_area()
    467     {
     361    public function loop_start_area() {
    468362        $recheck = $this->getRecheck('loop_start');
    469 
    470         if (! isset($recheck)) {
     363        if(!isset($recheck)){
    471364            echo $this->getCode('loop_start');
    472365        }
    473366    }
    474367
    475     public function loop_end_area()
    476     {
     368    public function loop_end_area() {
    477369        $recheck = $this->getRecheck('loop_end');
    478 
    479         if (! isset($recheck)) {
     370        if(!isset($recheck)){
    480371            echo $this->getCode('loop_end');
    481372        }
    482373    }
    483374
    484     public function comment_form_before_area()
    485     {
     375    public function comment_form_before_area() {
    486376        echo $this->getCode('comment_form_before');
    487377    }
    488    
    489     public function comment_form_after_area()
    490     {
     378
     379    public function comment_form_after_area() {
    491380        echo $this->getCode('comment_form_after');
    492381    }
    493        
    494     public function dynamic_sidebar_before_area()
    495     {
     382
     383    public function dynamic_sidebar_before_area() {
    496384        $recheck = $this->getRecheck('dynamic_sidebar_before');
    497 
    498         if (! isset($recheck)) {
     385        if(!isset($recheck)){
    499386            echo $this->getCode('dynamic_sidebar_before', 'small');
    500387        }
    501     }   
    502 
    503     public function dynamic_sidebar_after_area()
    504     {
     388    }
     389
     390    public function dynamic_sidebar_after_area() {
    505391        $recheck = $this->getRecheck('dynamic_sidebar_after');
    506 
    507         if (! isset($recheck)) {
     392        if(!isset($recheck)){
    508393            echo $this->getCode('dynamic_sidebar_after', 'small');
    509394        }
    510395    }
    511    
    512     public function content_after_area($content)
    513     {
     396
     397    public function content_after_area($content) {
    514398        $recheck = $this->getRecheck('content_after');
    515 
    516         if (! isset($recheck)) {
     399        if(!isset($recheck)){
    517400            $adnblock = $this->getCode('content_after');
    518             $content = $content . $adnblock;
    519         }
    520 
     401            $content = $content.$adnblock;
     402        }
    521403        return $content;
    522404    }
    523405
    524     /*
    525      *
    526      */
    527     public function content_before_area($content)
    528     {
     406    public function content_before_area($content) {
    529407        $recheck = $this->getRecheck('content_before');
    530 
    531         if (! isset($recheck)) {
     408        if(!isset($recheck)){
    532409            $adnblock = $this->getCode('content_before');
    533             $content = $adnblock . $content;
    534         }
    535 
     410            $content = $adnblock.$content;
     411        }
    536412        return $content;
    537413    }
    538414
    539     /*
    540      * Content of the displayed post excerpt (for the first post)
    541      */
    542     public function excerpt_after_area($content)
    543     {
     415    public function excerpt_after_area($content) {
    544416        $recheck = $this->getRecheck('the_excerpt');
    545 
    546         if (! isset($recheck)) {
     417        if(!isset($recheck)){
    547418            $adnblock = $this->getCode('the_excerpt');
    548             $content = $content . $adnblock;
    549         }
    550 
     419            $content = $content.$adnblock;
     420        }
    551421        return $content;
    552422    }
    553423
    554     /*
    555      * Content of the Custom HTML widget
    556      */
    557     public function widget_custom_html_content_area($content)
    558     {
    559         $recheck = $this->getRecheck('widget_custom_html_content');
    560 
    561         if (! isset($recheck)) {
    562             $adnblock = $this->getCode('widget_custom_html_content');
    563             $content = $content . $adnblock;
    564         }
    565 
     424    public function get_the_archive_title_area($content) {
     425        $adnblock = $this->getCode('get_the_archive_title');
     426        $content = $content.$adnblock;
    566427        return $content;
    567428    }
    568429
    569     /*
    570      * Content of the Text widget
    571      */
    572     public function widget_text_content_area($content)
    573     {
    574         $recheck = $this->getRecheck('widget_text_content');
    575 
    576         if (! isset($recheck)) {
    577             $adnblock = $this->getCode('widget_text_content');
    578             $content = $content . $adnblock;
    579         }
    580 
    581         return $content;
    582     }
    583 
    584 
    585 
    586     public function is_user_role($role, $user_id = null)
    587     {
    588         $user = is_numeric($user_id) ? get_userdata($user_id) : wp_get_current_user();
    589 
    590         if (! $user) {
    591             return false;
    592         }
    593 
    594         return in_array($role, (array) $user->roles);
     430    public function is_user_role( $role, $user_id = null ) {
     431        $user = is_numeric( $user_id ) ? get_userdata( $user_id ) : wp_get_current_user();
     432
     433        if( ! $user )
     434            return false;
     435
     436        return in_array( $role, (array) $user->roles );
    595437    }
    596438
    597439    public function empty_povt() {
    598 
    599440        global $wpdb;
    600441
    601442        foreach ($this->page_area_all as $key => $row) {
    602 
    603443            foreach ($this->page_type_all as $add) {
    604                 $wpdb->delete($wpdb->options, array( 'option_name' => $row . '_add_' . $add));
     444                $wpdb->delete($wpdb->options, array( 'option_name' => $row.'_add_'.$add));
    605445            }
    606446        }
    607447    }
    608448
    609     public function add_obhod()
    610     {
     449    public function add_obhod() {
    611450        $options_turn = get_option( $this->option_name . '_turn' );
    612 
    613         if (! empty($options_turn)) {
    614 
    615             if (! empty($this->aabd)) {
     451        if(!empty($options_turn)){
     452            if(!empty($this->aabd)){
    616453                echo base64_decode($this->aabd);
    617454            }
     
    619456    }
    620457
    621 
    622     public function modify_admin_bar( $wp_admin_bar )
    623     {
    624         $args = array(
    625             'id'    => 'edit_place',
    626             'title' => 'Edit place Adnow',
    627             'href'  => admin_url() . 'admin.php?page=edit_place&url=' . $this->request_uri,
    628             'meta'  => array( 'class' => 'my-toolbar-page' )
    629         );
    630 
    631         $wp_admin_bar->add_node( $args );
    632     }
    633 
    634     public function warning_handler($errno, $errstr)
    635     {
     458    public function modify_admin_bar( $wp_admin_bar ) {
     459        $token = get_option( $this->option_name . '_key' );
     460        set_error_handler(array($this, "warning_handler"), E_WARNING);
     461    $json = file_get_contents(API_URL . '?token=' . $token . '&validate=1');
     462        restore_error_handler();
     463        $widgets = json_decode($json, true);
     464        if($widgets["validate"] !== false and $this->getPluginStatus() !== true){
     465            $args = array(
     466                'id'    => 'edit_place',
     467                'title' => 'Edit place Adnow',
     468                'href'  => admin_url().'admin.php?page=edit_place&url='.$this->request_uri,
     469                'meta'  => array( 'class' => 'my-toolbar-page' )
     470            );
     471        }else{
     472            $args = array(
     473                'id'    => 'adnow_widget',
     474                'title' => 'Adnow Native Widget',
     475                'href'  => admin_url().'admin.php?page=adnow-widget',
     476                'meta'  => array( 'class' => 'my-toolbar-page' )
     477            );
     478        }
     479        $wp_admin_bar->add_node( $args );
     480    }
     481
     482    public function warning_handler($errno, $errstr) {
    636483        return false;
    637484    }
Note: See TracChangeset for help on using the changeset viewer.