Plugin Directory

Changeset 2578803


Ignore:
Timestamp:
08/05/2021 02:09:32 PM (5 years ago)
Author:
bingwebmastertools
Message:

wordpress compatibility version update to 5.8

Location:
bing-webmaster-tools
Files:
56 added
9 edited

Legend:

Unmodified
Added
Removed
  • bing-webmaster-tools/trunk/README.md

    r2535418 r2578803  
    6464## Changelog
    6565
     66### 1.0.13
     67- Fix: Compatibility update with wordpress v5.8 and linting fixes.
     68
    6669### 1.0.12
    6770- Fix: Compatibility issue with older wordpress versions.
  • bing-webmaster-tools/trunk/admin/class-bing-url-submission-admin.php

    r2535418 r2578803  
    3131
    3232    private $routes;
    33 
     33   
    3434    /**
    3535     * Initialize the class and set its properties.
     
    162162        }
    163163        if ($is_change) {
    164             if (isset($is_valid_api_key) && $is_valid_api_key && $auto_submission_enabled && $auto_submission_enabled == "1") {
     164            if (isset($is_valid_api_key) && $is_valid_api_key && $auto_submission_enabled && $auto_submission_enabled === "1") {
    165165                $link = get_permalink($post);
    166166                // remove __trashed from page url
     
    196196
    197197                $siteUrl = get_home_url();
     198
    198199                // check if same url was submitted recently(within a minute)
    199200                if ($new_status != 'trash' && Bing_Webmaster_Admin_Utils::url_submitted_within_last_minute(Bing_Webmaster_Admin_Routes::$passed_submissions_table, $link)) {
  • bing-webmaster-tools/trunk/admin/utils/class-bing-url-submission-admin-routes.php

    r2530162 r2578803  
    545545                } else {
    546546                    if ($is_valid_api_key && $is_valid_api_key === "1") {
    547                         $parsedUrl = parse_url($url);
     547                        $parsedUrl = wp_parse_url($url);
    548548                        $siteUrl = get_home_url();
    549549                        $output = $this->submit_url_to_bwt($siteUrl, $url, $api_key, "add", true);
  • bing-webmaster-tools/trunk/admin/utils/class-bing-url-submission-admin-utils.php

    r2342339 r2578803  
    1010 */
    1111class Bing_Webmaster_Admin_Utils {
    12     // This function finds out the ocunt of submissions in last 48 hours
    13     public static function get_count(SubmissionCount $submission_count) {
    14         $curr_time = time();
    15         Bing_Webmaster_Admin_Utils::set_last_date($submission_count, $curr_time);
    16         $count = 0;
    17         for ($i = 0; $i < 48; $i++) {
    18             $count += $submission_count->hourly_count[$i];
    19         }
    20         return $count;
    21     }
     12    /**
     13     * This function finds out the ocunt of submissions in last 48 hours.
     14     */
     15    public static function get_count( SubmissionCount $submission_count ) {
     16        $curr_time = time();
     17        self::set_last_date( $submission_count, $curr_time );
     18        $count = 0;
     19        for ( $i = 0; $i < 48; $i++ ) {
     20            $count += $submission_count->hourly_count[ $i ];
     21        }
     22        return $count;
     23    }
    2224
    23     // Increase the count by 1
    24     public static function increase_count(SubmissionCount $submission_count) {
    25         $curr_time = time();
    26         Bing_Webmaster_Admin_Utils::set_last_date($submission_count, $curr_time);
    27         $submission_count->hourly_count[$submission_count->index]++;
    28     }
     25    /**
     26     * Increase the count by 1.
     27     */
     28    public static function increase_count( SubmissionCount $submission_count ) {
     29        $curr_time = time();
     30        self::set_last_date( $submission_count, $curr_time );
     31        $submission_count->hourly_count[ $submission_count->index ]++;
     32    }
    2933
    30     // Set the last date when count was accessed/increased.
    31     // We store the count in array of size 48, count per hour so that we don't need to store every submission
    32     private static function set_last_date(SubmissionCount $submission_count, $curr_time) {
    33         $curr_hour = (int)($curr_time/3600);
    34         $last_hour = (int)($submission_count->last_count_date/3600);
    35         if ($curr_hour - $last_hour <= 48) {
    36             $i = 0;
    37             for ($i = ($submission_count->index + 1) % 48; $last_hour < $curr_hour; $i = ($i + 1) % 48, $last_hour++) {
    38                 $submission_count->hourly_count[$i] = 0;
    39             }
    40             $submission_count->index = ($i + 47) % 48;
    41         }
    42         else {
    43             for ($i = 0; $i < 48; $i++) {
    44                 $submission_count->hourly_count[$i] = 0;
    45             }
    46             $submission_count->index = $curr_hour % 24;
    47         }
    48         $submission_count->last_count_date = $curr_time;
    49     }
     34    /**
     35     * Set the last date when count was accessed/increased.
     36     * We store the count in array of size 48, count per hour so that we don't need to store every submission.
     37     */
     38    private static function set_last_date( SubmissionCount $submission_count, $curr_time ) {
     39        $curr_hour = (int) ( $curr_time / 3600 );
     40        $last_hour = (int) ( $submission_count->last_count_date / 3600 );
     41        if ( $curr_hour - $last_hour <= 48 ) {
     42            $i = 0;
     43            for ( $i = ( $submission_count->index + 1 ) % 48; $last_hour < $curr_hour; $i = ( $i + 1 ) % 48, $last_hour++ ) {
     44                $submission_count->hourly_count[ $i ] = 0;
     45            }
     46            $submission_count->index = ( $i + 47 ) % 48;
     47        } else {
     48            for ( $i = 0; $i < 48; $i++ ) {
     49                $submission_count->hourly_count[ $i ] = 0;
     50            }
     51            $submission_count->index = $curr_hour % 24;
     52        }
     53        $submission_count->last_count_date = $curr_time;
     54    }
    5055
    51     public static function get_submissions($table) {
    52         global $wpdb;
    53         $table_name = $wpdb->prefix . $table;
    54         $date = time() - 48 * 60 * 60;
    55         $query = "SELECT * FROM {$table_name} WHERE submission_date > {$date} ORDER BY submission_date DESC LIMIT 21";
    56         $results = $wpdb->get_results( $query, OBJECT );
    57         if (is_array($results) && count($results) === 21) {
    58             $ids = array();
    59             $results = array_slice($results, 0, 20);
    60             foreach ($results as $result) {
    61                 array_push($ids, $result->id);
    62             }
    63             $res = $wpdb->query(
    64                 "DELETE FROM {$table_name}
    65                 WHERE id not in (".implode(',',$ids).")"
    66             );
    67         }
    68         return $results;
    69     }
     56    /**
     57     * This function retrieves the latest submitted urls upto 20.
     58     *  It deletes the older submitted urls from the table.
     59     */
     60    public static function get_submissions( $table ) {
     61        global $wpdb;
     62        $table_name = $wpdb->prefix . $table;
     63        $date = time() - 48 * 60 * 60;
     64            $results = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $table_name . ' WHERE submission_date > %d ORDER BY submission_date DESC LIMIT 21', $date ), OBJECT );
     65        if ( is_array( $results ) && count( $results ) === 21 ) {
     66            $ids = array();
     67            $results = array_slice( $results, 0, 20 );
     68            foreach ( $results as $result ) {
     69                array_push( $ids, $result->id );
     70            }
     71            $res = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $table_name . ' WHERE id not in ( %s )', implode( ',', $ids ) ) );
     72        }
     73        return $results;
     74    }
    7075
    71     public static function url_submitted_within_last_minute($table, $url) {
    72         global $wpdb;
    73         $table_name = $wpdb->prefix . $table;
    74         $date = time() - 60;
    75         $query = "SELECT * FROM {$table_name} WHERE submission_date > {$date} AND url = '" . $url . "' LIMIT 1";
    76         $results = $wpdb->get_results( $query, OBJECT );
    77         return is_array($results) && count($results) > 0;
    78     }
     76    public static function url_submitted_within_last_minute( $table, $url ) {
     77        global $wpdb;
     78        $table_name = $wpdb->prefix . $table;
     79        $date = time() - 60;
     80        $results = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $table_name . ' WHERE submission_date > %d AND url =  %s LIMIT 1', array( $date, $url ) ), OBJECT );
     81        return is_array( $results ) && count( $results ) > 0;
     82    }
    7983
    80     public static function insert_submission($table, Submissions $submission) {
    81         global $wpdb;
    82         $table_name = $wpdb->prefix . $table;
    83         $results = $wpdb->insert( $table_name, array(
    84             'url' => $submission->url,
    85             'submission_type' => $submission->submission_type,
    86             'submission_date' => $submission->submission_date,
    87             'error' => $submission->error,
    88             'type' => $submission->type
    89         ) );
    90     }
     84    public static function insert_submission( $table, Submissions $submission ) {
     85        global $wpdb;
     86        $table_name = $wpdb->prefix . $table;
     87        $results = $wpdb->insert(
     88            $table_name,
     89            array(
     90                'url' => $submission->url,
     91                'submission_type' => $submission->submission_type,
     92                'submission_date' => $submission->submission_date,
     93                'error' => $submission->error,
     94                'type' => $submission->type,
     95            )
     96        );
     97    }
    9198
    92     public static function delete_submissions($table) {
    93         global $wpdb;
    94         $table_name = $wpdb->prefix . $table;
    95         $results = $wpdb->query($wpdb->prepare(
    96             'DELETE FROM $table_name'
    97         ));
    98         return $results;
    99     }
     99    public static function delete_submissions( $table ) {
     100        global $wpdb;
     101        $table_name = $wpdb->prefix . $table;
     102        //phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
     103        $results = $wpdb->query( 'DELETE FROM ' . $table_name );
     104        return $results;
     105        //phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
     106    }
    100107
    101     public static function is_localhost($ip = ['127.0.0.1', '::1']) {
    102         return in_array($_SERVER['REMOTE_ADDR'], $ip);
    103     }
     108    public static function is_localhost( $ip = array( '127.0.0.1', '::1' ) ) {
     109        return in_array( $_SERVER['REMOTE_ADDR'], $ip );
     110    }
    104111}
    105112
    106113class SubmissionCount {
    107114
    108     public function __construct() {
     115    public function __construct() {
    109116
    110         $this->hourly_count = array();
    111         for ($i = 0; $i < 48; $i++) {
    112             array_push($this->hourly_count, 0);
    113         }
     117        $this->hourly_count = array();
     118        for ( $i = 0; $i < 48; $i++ ) {
     119            array_push( $this->hourly_count, 0 );
     120        }
    114121        $this->last_count_date = time();
    115122
    116123    }
    117124
    118     public $hourly_count;
    119     public $last_count_date;
    120     public $index;
     125    public $hourly_count;
     126    public $last_count_date;
     127    public $index;
    121128}
  • bing-webmaster-tools/trunk/asset-manifest.json

    r2495657 r2578803  
    11{
    22  "files": {
    3     "main.css": "/static/css/main.0877b1c8.chunk.css",
    4     "main.js": "/static/js/main.34b1d57d.chunk.js",
    5     "main.js.map": "/static/js/main.34b1d57d.chunk.js.map",
    6     "runtime-main.js": "/static/js/runtime-main.83546e98.js",
    7     "runtime-main.js.map": "/static/js/runtime-main.83546e98.js.map",
    8     "static/js/2.ce134f0c.chunk.js": "/static/js/2.ce134f0c.chunk.js",
    9     "static/js/2.ce134f0c.chunk.js.map": "/static/js/2.ce134f0c.chunk.js.map",
     3    "main.css": "/static/css/main.65f16462.chunk.css",
     4    "main.js": "/static/js/main.61ee0758.chunk.js",
     5    "main.js.map": "/static/js/main.61ee0758.chunk.js.map",
     6    "runtime-main.js": "/static/js/runtime-main.7009c118.js",
     7    "runtime-main.js.map": "/static/js/runtime-main.7009c118.js.map",
     8    "static/js/2.b3eea4c5.chunk.js": "/static/js/2.b3eea4c5.chunk.js",
     9    "static/js/2.b3eea4c5.chunk.js.map": "/static/js/2.b3eea4c5.chunk.js.map",
    1010    "index.html": "/index.html",
    11     "static/css/main.0877b1c8.chunk.css.map": "/static/css/main.0877b1c8.chunk.css.map",
    12     "static/js/2.ce134f0c.chunk.js.LICENSE.txt": "/static/js/2.ce134f0c.chunk.js.LICENSE.txt"
     11    "static/css/main.65f16462.chunk.css.map": "/static/css/main.65f16462.chunk.css.map",
     12    "static/js/2.b3eea4c5.chunk.js.LICENSE.txt": "/static/js/2.b3eea4c5.chunk.js.LICENSE.txt"
    1313  },
    1414  "entrypoints": [
    15     "static/js/runtime-main.83546e98.js",
    16     "static/js/2.ce134f0c.chunk.js",
    17     "static/css/main.0877b1c8.chunk.css",
    18     "static/js/main.34b1d57d.chunk.js"
     15    "static/js/runtime-main.7009c118.js",
     16    "static/js/2.b3eea4c5.chunk.js",
     17    "static/css/main.65f16462.chunk.css",
     18    "static/js/main.61ee0758.chunk.js"
    1919  ]
    2020}
  • bing-webmaster-tools/trunk/bing-url-submission.php

    r2535418 r2578803  
    1010 * Plugin URI:        https://www.bing.com/webmaster
    1111 * Description:       A small plugin to allow Url submissions to Bing Webmaster Tools.
    12  * Version:           1.0.12
     12 * Version:           1.0.13
    1313 * Author:            Bing Webmaster
    1414 * Author URI:        https://www.bing.com/webmaster
     
    2727 * Currently plugin version.
    2828 */
    29 define( 'BWT_URL_SUBMISSION_PLUGIN_VERSION', '1.0.12' );
     29define( 'BWT_URL_SUBMISSION_PLUGIN_VERSION', '1.0.13' );
    3030
    3131/**
  • bing-webmaster-tools/trunk/includes/class-bing-url-submission-deactivator.php

    r2342339 r2578803  
    2020     * @since    0.01.01
    2121     */
    22     public static function deactivate($plugin_name) {
    23         delete_option("bwt-failed_count");
    24         delete_option("bwt-passed_count");
    25         delete_option("bwt-is_valid_api_key");
    26         delete_option("bwt-admin_api_key");
    27         delete_option("bwt-auto_submission_enabled");
     22    public static function deactivate( $plugin_name ) {
     23        delete_option( 'bwt-failed_count' );
     24        delete_option( 'bwt-passed_count' );
     25        delete_option( 'bwt-is_valid_api_key' );
     26        delete_option( 'bwt-admin_api_key' );
     27        delete_option( 'bwt-auto_submission_enabled' );
    2828
    2929        global $wpdb;
    30    
     30
    3131        $table_name = $wpdb->prefix . 'bwt_failed_submissions';
    32         $wpdb->query("DROP TABLE {$table_name}");
    33 
     32        //phpcs:disable
     33        $wpdb->query( 'DROP TABLE  ' . $table_name );
     34        //phpcs:enable
    3435        $table_name = $wpdb->prefix . 'bwt_passed_submissions';
    35         $wpdb->query("DROP TABLE {$table_name}");
     36        //phpcs:disable
     37        $wpdb->query( 'DROP TABLE  ' . $table_name );
     38        //phpcs:enable
    3639    }
    3740
  • bing-webmaster-tools/trunk/includes/class-bing-url-submission.php

    r2535418 r2578803  
    5656            $this->version = BWT_URL_SUBMISSION_PLUGIN_VERSION;
    5757        } else {
    58             $this->version = '1.0.12';
     58            $this->version = '1.0.13';
    5959        }
    6060        $this->plugin_name = $plugin_name;
     
    110110        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
    111111
    112         // Save/Update our plugin options
     112        // Save/Update our plugin options.
    113113        $this->loader->add_action( 'admin_init', $plugin_admin, 'options_update');
    114114
    115115        $this->loader->add_action( 'rest_api_init', $plugin_admin, 'register_routes');
    116116
    117         // Add a new admin menu
     117        // Add a new admin menu.
    118118        $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_admin_menu' );
    119119
    120         // Add Settings link to the plugin
     120        // Add Settings link to the plugin.
    121121        $plugin_basename = plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_name . '.php' );
    122122        $this->loader->add_filter( 'plugin_action_links_' . $plugin_basename, $plugin_admin, 'add_action_links' );
    123123
    124         // Add url submit action & post publishing
     124        // Add url submit action & post publishing.
    125125        $this->loader->add_action( 'transition_post_status', $plugin_admin, 'on_post_published', 10, 3 );
    126126    }
  • bing-webmaster-tools/trunk/readme.txt

    r2535418 r2578803  
    44Tags: seo, crawling
    55Requires at least: 5.3
    6 Tested up to: 5.7
    7 Stable tag: 1.0.12
     6Tested up to: 5.8
     7Stable tag: 1.0.13
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.txt
     
    7575== Changelog ==
    7676
     77= 1.0.13 =
     78- Fix: Compatibility update with wordpress v5.8 and linting fixes.
     79
    7780= 1.0.12 =
    7881- Fix: Compatibility issue with older wordpress versions.
Note: See TracChangeset for help on using the changeset viewer.