Plugin Directory

Changeset 2458380


Ignore:
Timestamp:
01/18/2021 04:09:39 PM (5 years ago)
Author:
GregLone
Message:

Update to version 4.0.0 from GitHub

Location:
sf-adminbar-tools
Files:
1424 added
6 deleted
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • sf-adminbar-tools/tags/4.0.0/readme.txt

    r1541504 r2458380  
    11=== Admin Bar Tools ===
    22Contributors: GregLone
    3 Tags: admin, admin bar, bar, query, screen, tool, dev, template
    4 Requires at least: 3.1
    5 Tested up to: 4.7.0
     3Tags: debug, query, development, testing, tests
     4Requires at least: 4.7
     5Tested up to: 5.6.0
    66Stable tag: trunk
    77License: GPLv3
    88
    9 Adds some small interesting tools to the admin bar for Developers.
     9Adds some small development tools to the admin bar.
    1010
    1111== Description ==
     
    1313
    1414* Displays the number of queries in your page and the amount of time to generate the page.
    15 * Displays php memory usage, php memory limit, and php version.
    16 * Display WP_DEBUG state and error reporting value.
     15* Displays the php memory usage and php memory limits (constants `WP_MEMORY_LIMIT` and `WP_MAX_MEMORY_LIMIT`).
     16* displays the php version and WP version.
     17* Displays `WP_DEBUG`, `SCRIPT_DEBUG`, `WP_DEBUG_LOG`, `WP_DEBUG_DISPLAY`, and error reporting values.
    1718
    1819**In your site front-end:**
    1920
    20 * List the template and all template parts used in the current page (template parts added with <code>get_template_part()</code>). Compatible with WooCommerce.
    21 * WP_Query: click the *$wp_query* item will open a lightbox with the content of $wp_query. Click the lightbox title to reload the value, click outside the lightbox to close it.
     21* Lists the template and all template parts used in the current page (template parts added with `get_template_part()`). Compatible with WooCommerce's templates.
     22* `$wp_query`: this will open a lightbox displaying the content of `$wp_query`. Click the lightbox title to reload the value, click outside the lightbox to close it.
    2223
    2324**In your site administration:**
    2425
    25 * Current screen: a dropdown containing lots of things:
    26 1. Three lists of useful hooks (actions). The indicator to the right of the line tells you how many times the hook has been triggered (a "x" means the plugin doesn't know, because the hook occurs after the admin bar). A "P" means the hook has a parameter: hover it for more details. Click a hook (on its text) to auto-select its code, for example: click *admin_init* to select <code>add_action( 'admin_init', '' );</code>.
    27 2. $...now: this dropdown contains the value of the well-known variables $pagenow, $typenow and $taxnow.
    28 3. Finally, you can know the current page id and base.
     26* Admin hooks: lists some oftenly used hooks (like `admin_init`). The indicator to the right of the line tells you how many times the hook has been triggered by a callback. A "P" means the hook has a parameter: hover it for more details. Click a hook (on its text) to auto-select its code, for example: click *admin_init* to select `add_action( 'admin_init', '' );`.
     27* `$current_screen`: displays the value of 4 properties of this object: `id`, `base`, `parent_base`, `parent_file`.
     28* `$...now`: displays the value of the well-known variables `$pagenow`, `$typenow`, and `$taxnow`.
     29* On a user profile page, `$userdata`: : this will open a lightbox displaying the user's data.
    2930
    3031You can decide who's gonna use this plugin (go to your profile page for all the settings). This way, the plugin's items won't show up to other users (your client for example).
    31 
    32 Version 3 is not tested with old versions of WordPress yet.
    33 
    34 = Translations =
    35 * English
    36 * French
    37 
    38 = Important note: browser requirement =
    39 You'll need a modern browser to use correctly this plugin. I used some CSS3 features without fallback to keep it simple (you don't work with a dinosaur, right?).
     32Also, a new menu item `Code Tester` will appear. There you are able to do some tests with your code.
    4033
    4134== Installation ==
     
    4841
    4942None, yet.
    50 Check out [the plugin page on my blog](https://www.screenfeed.fr/plugin-wp/sf-admin-bar-tools/) for more infos or tips (sorry guys, it's in French, but feel free to leave a comment in English if you need help).
    5143
    5244== Screenshots ==
    5345
    54 1. Admin side: list the most important hooks "before headers".
     461. Admin side: list the most important hooks in the admin area.
    55472. Admin side: click a hook, you're ready to copy/paste.
    56 3. Front side: see the <code>WP_Query</code> object value.
     483. Front side: see the `WP_Query` object value.
    57494. Front side: see the template and list all template parts used in the current page.
    58 5. By the way, WooCommerce templates are also listed.
    59 6. The settings in your profile page.
     505. The settings in your profile page.
     516. The code tester area.
    6052
    6153== Changelog ==
     54
     55= 4.0.0 =
     56* 2021/01/15
     57* The plugin has been totally rewritten. It requires at least php 5.6 and WP 4.7, and is ready for WP 5.6.
     58* Items' arrangement is a bit more clear, less cryptic.
     59* Templates: if arguments are passed to the template via `get_template_part()` (new in WP 5.5), a "P" will appear at the right of the row: hovering this "P" will display these arguments.
     60* Added: the value of the constants `WP_MAX_MEMORY_LIMIT`, `SCRIPT_DEBUG`, `WP_DEBUG_LOG`, and `WP_DEBUG_DISPLAY`. Also the WordPress' version.
     61* About the lightbox displaying the value of `$wp_query`: this lightbow is now also used to display a user's data on a user's profile page (admin area). This lightbox can be filtered/extended to display anything you want in frontend or admin.
     62* A new menu item "Code Tester" to test your code rapidly.
     63* Improvement: this tool being displayed in the admin bar, some values were inaccurate or incomplete (everything happening after the admin bar wasn't taken into account). This has been fixed for the number of requests, page load time, admin hooks, and memory usage.
     64* Fix: the plugin forces the admin bar to be printed at the bottom of the page on frontend, instead of using the new hook `wp_body_open`. This is done to be able to list all template parts.
     65* The plugin is now using a template loader that can be filtered to customize the way everything is displayed.
    6266
    6367= 3.0.4 =
     
    7377= 3.0.2 =
    7478* 2015/11/07
    75 * Bugfix: avoid annoying message caused by <code>is_embed()</code> in WP 4.4.0.
     79* Bugfix: avoid annoying message caused by `is_embed()` in WP 4.4.0.
    7680
    7781= 3.0.1 =
  • sf-adminbar-tools/tags/4.0.0/sf-adminbar-tools.php

    r1541503 r2458380  
    11<?php
    2 /*
    3  * Plugin Name: SF Admin bar tools
     2/**
     3 * Plugin Name: SF Admin Bar Tools
    44 * Plugin URI: https://www.screenfeed.fr/sf-abt/
    5  * Description: Adds some small interesting tools to the admin bar for developers.
    6  * Version: 3.0.4
     5 * Description: Adds some small development tools to the admin bar.
     6 * Version: 4.0
     7 * Requires PHP: 5.6
    78 * Author: Grégory Viguier
    89 * Author URI: https://www.screenfeed.fr/greg/
     
    1112 * Text Domain: sf-adminbar-tools
    1213 * Domain Path: /languages/
     14 * php version 5.2
     15 *
     16 * @package Screenfeed/sf-adminbar-tools
    1317 */
    1418
     19defined( 'ABSPATH' ) || exit; // @phpstan-ignore-line
    1520
    16 if ( ! defined( 'ABSPATH' ) ) {
    17     die( 'Cheatin\' uh?' );
    18 }
     21define( 'SFABT_VERSION', '4.0' );
    1922
    20 if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) ) {
    21     return;
    22 }
    23 
    24 
    25 define( 'SFABT_VERSION',         '3.0.4' );
    26 define( 'SFABT_FILE',            __FILE__ );
    27 define( 'SFABT_PLUGIN_URL',      plugin_dir_url( SFABT_FILE ) );
    28 define( 'SFABT_PLUGIN_DIR',      plugin_dir_path( SFABT_FILE ) );
    29 define( 'SFABT_PLUGIN_BASENAME', plugin_basename( SFABT_FILE ) );
    30 
    31 if ( ! defined( 'SFABT_CAP' ) ) {
    32     // Can be a role or a capability.
    33     define( 'SFABT_CAP',         'administrator' );
    34 }
    35 if ( ! defined( 'SFABT_DEBUG' ) ) {
    36     define( 'SFABT_DEBUG',       false );
    37 }
    38 
    39 
    40 /*------------------------------------------------------------------------------------------------*/
    41 /* !INCLUDES ==================================================================================== */
    42 /*------------------------------------------------------------------------------------------------*/
    43 
    44 add_action( 'set_current_user', 'sfabt_includes', 1 );
    45 
    46 function sfabt_includes() {
    47     global $pagenow;
    48     static $done = false;
    49 
    50     if ( $done ) {
     23add_action( 'plugins_loaded', 'sfabt_plugin_init' );
     24/**
     25 * Initializes the plugin.
     26 *
     27 * @since 4.0.0
     28 *
     29 * @return void
     30 */
     31function sfabt_plugin_init() {
     32    // Nothing to do during autosave.
     33    if ( defined( 'DOING_AUTOSAVE' ) ) {
    5134        return;
    5235    }
    5336
    54     $done    = true;
    55     $user_id = get_current_user_id();
     37    $plugin_dir  = plugin_dir_path( __FILE__ );
     38    $plugin_name = 'SF Admin Bar Tools';
    5639
    57     include( SFABT_PLUGIN_DIR . 'inc/general.php' );
     40    // Check for WordPress and PHP version.
     41    require_once $plugin_dir . '/src/class-sfabt-requirements-check.php';
    5842
    59     // Check we have at least one coworker. If not, add the current user if eligible.
    60     if ( sfabt_is_eligible_user( $user_id ) && ! sfabt_coworkers_have_admin() && ! sfabt_is_coworker() ) {
    61         $options = sfabt_get_options();
    62         $options['coworkers'][] = $user_id;
    63         sfabt_update_options( $options );
    64     }
     43    $requirement_checks = new SFABT_Requirements_Check(
     44        array(
     45            'plugin_name'    => $plugin_name,
     46            'plugin_version' => SFABT_VERSION,
     47            'wp_version'     => '4.7',
     48            'php_version'    => '5.6',
     49        )
     50    );
    6551
    66     // Stop here for non-coworkers or if it's an ajjax call.
    67     if ( doing_ajax() || ! sfabt_is_coworker() ) {
     52    if ( ! $requirement_checks->check() ) {
     53        $requirement_checks->add_notice();
    6854        return;
    6955    }
    7056
    71     $show = sfabt_is_admin_bar_showing();
     57    // Init the plugin.
     58    require_once $plugin_dir . '/src/classes/Plugin.php';
    7259
    73     if ( $show ) {
    74         include( SFABT_PLUGIN_DIR . 'inc/adminbar-items.php' );
     60    $plugin = call_user_func(
     61        array( 'Screenfeed\AdminbarTools\Plugin', 'construct' ),
     62        array(
     63            'plugin_file' => __FILE__,
     64            'plugin_name' => $plugin_name,
     65        )
     66    );
     67
     68    $plugin->init();
     69}
     70
     71/**
     72 * Returns the user capacity required to operate the plugin.
     73 *
     74 * @since 4.0.0
     75 *
     76 * @return string A user capacity or user role.
     77 */
     78function sfabt_get_user_capacity() {
     79    static $cap;
     80
     81    if ( isset( $cap ) ) {
     82        return $cap;
    7583    }
    7684
    77     if ( is_admin() ) {
    78         include( SFABT_PLUGIN_DIR . 'inc/admin.php' );
     85    if ( defined( 'SFABT_CAP' ) && is_string( SFABT_CAP ) && '' !== SFABT_CAP ) {
     86        $cap = SFABT_CAP;
     87    } else {
     88        $cap = 'administrator';
     89    }
    7990
    80         if ( $show ) {
    81             include( SFABT_PLUGIN_DIR . 'inc/adminbar-items-admin.php' );
    82         }
    83 
    84         if ( 'profile.php' === $pagenow && defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) {
    85             include( SFABT_PLUGIN_DIR . 'inc/profile.php' );
    86         }
    87     } elseif ( is_frontend() && $show ) {
    88         include( SFABT_PLUGIN_DIR . 'inc/adminbar-items-frontend.php' );
    89     }
     91    return $cap;
    9092}
    9193
    92 
    93 /*------------------------------------------------------------------------------------------------*/
    94 /* !TOOLS ======================================================================================= */
    95 /*------------------------------------------------------------------------------------------------*/
    96 
    97 /*
    98  * A better <code>print_r()</code>, wrapped in a styled <code>&lt;pre&gt;</code> tag.
     94/**
     95 * Loads the plugin translations.
     96 * Previously named `sfabt_lang_init()`.
    9997 *
    100  * $var                     (mixed)    Variable to print out.
    101  * $display                 (bool|int) When false (default), print a "display: none" in the <code>&lt;pre&gt;</code> style. This way, you'll have to manually remove it (with firebug or any other tool), so you don't bother other users. But be aware that you can still break things.
    102  * $print_for_non_logged_in (bool|int) When false (default), nothing will be printed for logged out users.
    103  * ex:
    104  * pre_print_r($var)      : printed only for logged in users, but hidden for everybody (remove the display:hidden by yourself in the page).
    105  * pre_print_r($var, 1)   : printed only for logged in users, all logged in users can see the code.
    106  * pre_print_r($var, 0, 1): printed for everybody (logged out users too), but hidden for everybody (remove the display:hidden by yourself in the page).
    107  * pre_print_r($var, 1, 1): printed for everybody (logged out users too), all users can see the code.
     98 * @since 4.0.0
     99 *
     100 * @return void
    108101 */
    109 
    110 if ( ! function_exists( 'pre_print_r' ) ) :
    111     function pre_print_r( $var, $display = false, $print_for_non_logged_in = false ) {
    112         if ( ! $print_for_non_logged_in && ! ( function_exists( 'is_user_logged_in' ) && is_user_logged_in() ) ) {
    113             return;
    114         }
    115 
    116         echo '<pre style="background:rgb(34,34,34);line-height:19px;font-size:14px;color:#fff;text-shadow:none;font-family:monospace;padding:6px 10px;margin:2px;position:relative;z-index:10000;overflow:auto;' . ( (bool) $display ? '' : 'display:none;' ) . '">';
    117             if ( ( is_string( $var ) && '' === trim( $var ) ) || is_bool( $var ) || null === $var ) {
    118                 var_dump( $var );
    119             } else {
    120                 print_r( $var );
    121             }
    122             echo '<div style="clear:both"></div>';
    123         echo "</pre>\n";
    124     }
    125 endif;
     102function sfabt_load_translations() {
     103    load_plugin_textdomain( 'sf-adminbar-tools', false, basename( dirname( __FILE__ ) ) . '/languages/' );
     104}
  • sf-adminbar-tools/tags/4.0.0/uninstall.php

    r1385704 r2458380  
    11<?php
    2 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
    3     exit();
    4 }
     2/**
     3 * What to do when the plugin is uninstalled.
     4 * php version 5.2
     5 *
     6 * @package Screenfeed/sf-adminbar-tools
     7 */
    58
     9defined( 'ABSPATH' ) || exit; // @phpstan-ignore-line
    610
    7 delete_option( 'sf-abt-open-files' );
    8 delete_option( '_sf_abt' );
    9 delete_metadata( 'user', 0, 'sf-abt-coworking', null, true );
    10 delete_metadata( 'user', 0, 'sf-abt-no-autosave', null, true );
    11 delete_metadata( 'user', 0, 'sf-abt-no-cowork-refresh', null, true );
     11delete_option( 'sfabt_settings' );
     12delete_site_option( 'sfabt_settings' );
     13delete_metadata( 'user', 0, 'sfabt-no-autosave', null, true );
  • sf-adminbar-tools/trunk/readme.txt

    r1541504 r2458380  
    11=== Admin Bar Tools ===
    22Contributors: GregLone
    3 Tags: admin, admin bar, bar, query, screen, tool, dev, template
    4 Requires at least: 3.1
    5 Tested up to: 4.7.0
     3Tags: debug, query, development, testing, tests
     4Requires at least: 4.7
     5Tested up to: 5.6.0
    66Stable tag: trunk
    77License: GPLv3
    88
    9 Adds some small interesting tools to the admin bar for Developers.
     9Adds some small development tools to the admin bar.
    1010
    1111== Description ==
     
    1313
    1414* Displays the number of queries in your page and the amount of time to generate the page.
    15 * Displays php memory usage, php memory limit, and php version.
    16 * Display WP_DEBUG state and error reporting value.
     15* Displays the php memory usage and php memory limits (constants `WP_MEMORY_LIMIT` and `WP_MAX_MEMORY_LIMIT`).
     16* displays the php version and WP version.
     17* Displays `WP_DEBUG`, `SCRIPT_DEBUG`, `WP_DEBUG_LOG`, `WP_DEBUG_DISPLAY`, and error reporting values.
    1718
    1819**In your site front-end:**
    1920
    20 * List the template and all template parts used in the current page (template parts added with <code>get_template_part()</code>). Compatible with WooCommerce.
    21 * WP_Query: click the *$wp_query* item will open a lightbox with the content of $wp_query. Click the lightbox title to reload the value, click outside the lightbox to close it.
     21* Lists the template and all template parts used in the current page (template parts added with `get_template_part()`). Compatible with WooCommerce's templates.
     22* `$wp_query`: this will open a lightbox displaying the content of `$wp_query`. Click the lightbox title to reload the value, click outside the lightbox to close it.
    2223
    2324**In your site administration:**
    2425
    25 * Current screen: a dropdown containing lots of things:
    26 1. Three lists of useful hooks (actions). The indicator to the right of the line tells you how many times the hook has been triggered (a "x" means the plugin doesn't know, because the hook occurs after the admin bar). A "P" means the hook has a parameter: hover it for more details. Click a hook (on its text) to auto-select its code, for example: click *admin_init* to select <code>add_action( 'admin_init', '' );</code>.
    27 2. $...now: this dropdown contains the value of the well-known variables $pagenow, $typenow and $taxnow.
    28 3. Finally, you can know the current page id and base.
     26* Admin hooks: lists some oftenly used hooks (like `admin_init`). The indicator to the right of the line tells you how many times the hook has been triggered by a callback. A "P" means the hook has a parameter: hover it for more details. Click a hook (on its text) to auto-select its code, for example: click *admin_init* to select `add_action( 'admin_init', '' );`.
     27* `$current_screen`: displays the value of 4 properties of this object: `id`, `base`, `parent_base`, `parent_file`.
     28* `$...now`: displays the value of the well-known variables `$pagenow`, `$typenow`, and `$taxnow`.
     29* On a user profile page, `$userdata`: : this will open a lightbox displaying the user's data.
    2930
    3031You can decide who's gonna use this plugin (go to your profile page for all the settings). This way, the plugin's items won't show up to other users (your client for example).
    31 
    32 Version 3 is not tested with old versions of WordPress yet.
    33 
    34 = Translations =
    35 * English
    36 * French
    37 
    38 = Important note: browser requirement =
    39 You'll need a modern browser to use correctly this plugin. I used some CSS3 features without fallback to keep it simple (you don't work with a dinosaur, right?).
     32Also, a new menu item `Code Tester` will appear. There you are able to do some tests with your code.
    4033
    4134== Installation ==
     
    4841
    4942None, yet.
    50 Check out [the plugin page on my blog](https://www.screenfeed.fr/plugin-wp/sf-admin-bar-tools/) for more infos or tips (sorry guys, it's in French, but feel free to leave a comment in English if you need help).
    5143
    5244== Screenshots ==
    5345
    54 1. Admin side: list the most important hooks "before headers".
     461. Admin side: list the most important hooks in the admin area.
    55472. Admin side: click a hook, you're ready to copy/paste.
    56 3. Front side: see the <code>WP_Query</code> object value.
     483. Front side: see the `WP_Query` object value.
    57494. Front side: see the template and list all template parts used in the current page.
    58 5. By the way, WooCommerce templates are also listed.
    59 6. The settings in your profile page.
     505. The settings in your profile page.
     516. The code tester area.
    6052
    6153== Changelog ==
     54
     55= 4.0.0 =
     56* 2021/01/15
     57* The plugin has been totally rewritten. It requires at least php 5.6 and WP 4.7, and is ready for WP 5.6.
     58* Items' arrangement is a bit more clear, less cryptic.
     59* Templates: if arguments are passed to the template via `get_template_part()` (new in WP 5.5), a "P" will appear at the right of the row: hovering this "P" will display these arguments.
     60* Added: the value of the constants `WP_MAX_MEMORY_LIMIT`, `SCRIPT_DEBUG`, `WP_DEBUG_LOG`, and `WP_DEBUG_DISPLAY`. Also the WordPress' version.
     61* About the lightbox displaying the value of `$wp_query`: this lightbow is now also used to display a user's data on a user's profile page (admin area). This lightbox can be filtered/extended to display anything you want in frontend or admin.
     62* A new menu item "Code Tester" to test your code rapidly.
     63* Improvement: this tool being displayed in the admin bar, some values were inaccurate or incomplete (everything happening after the admin bar wasn't taken into account). This has been fixed for the number of requests, page load time, admin hooks, and memory usage.
     64* Fix: the plugin forces the admin bar to be printed at the bottom of the page on frontend, instead of using the new hook `wp_body_open`. This is done to be able to list all template parts.
     65* The plugin is now using a template loader that can be filtered to customize the way everything is displayed.
    6266
    6367= 3.0.4 =
     
    7377= 3.0.2 =
    7478* 2015/11/07
    75 * Bugfix: avoid annoying message caused by <code>is_embed()</code> in WP 4.4.0.
     79* Bugfix: avoid annoying message caused by `is_embed()` in WP 4.4.0.
    7680
    7781= 3.0.1 =
  • sf-adminbar-tools/trunk/sf-adminbar-tools.php

    r1541503 r2458380  
    11<?php
    2 /*
    3  * Plugin Name: SF Admin bar tools
     2/**
     3 * Plugin Name: SF Admin Bar Tools
    44 * Plugin URI: https://www.screenfeed.fr/sf-abt/
    5  * Description: Adds some small interesting tools to the admin bar for developers.
    6  * Version: 3.0.4
     5 * Description: Adds some small development tools to the admin bar.
     6 * Version: 4.0
     7 * Requires PHP: 5.6
    78 * Author: Grégory Viguier
    89 * Author URI: https://www.screenfeed.fr/greg/
     
    1112 * Text Domain: sf-adminbar-tools
    1213 * Domain Path: /languages/
     14 * php version 5.2
     15 *
     16 * @package Screenfeed/sf-adminbar-tools
    1317 */
    1418
     19defined( 'ABSPATH' ) || exit; // @phpstan-ignore-line
    1520
    16 if ( ! defined( 'ABSPATH' ) ) {
    17     die( 'Cheatin\' uh?' );
    18 }
     21define( 'SFABT_VERSION', '4.0' );
    1922
    20 if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) ) {
    21     return;
    22 }
    23 
    24 
    25 define( 'SFABT_VERSION',         '3.0.4' );
    26 define( 'SFABT_FILE',            __FILE__ );
    27 define( 'SFABT_PLUGIN_URL',      plugin_dir_url( SFABT_FILE ) );
    28 define( 'SFABT_PLUGIN_DIR',      plugin_dir_path( SFABT_FILE ) );
    29 define( 'SFABT_PLUGIN_BASENAME', plugin_basename( SFABT_FILE ) );
    30 
    31 if ( ! defined( 'SFABT_CAP' ) ) {
    32     // Can be a role or a capability.
    33     define( 'SFABT_CAP',         'administrator' );
    34 }
    35 if ( ! defined( 'SFABT_DEBUG' ) ) {
    36     define( 'SFABT_DEBUG',       false );
    37 }
    38 
    39 
    40 /*------------------------------------------------------------------------------------------------*/
    41 /* !INCLUDES ==================================================================================== */
    42 /*------------------------------------------------------------------------------------------------*/
    43 
    44 add_action( 'set_current_user', 'sfabt_includes', 1 );
    45 
    46 function sfabt_includes() {
    47     global $pagenow;
    48     static $done = false;
    49 
    50     if ( $done ) {
     23add_action( 'plugins_loaded', 'sfabt_plugin_init' );
     24/**
     25 * Initializes the plugin.
     26 *
     27 * @since 4.0.0
     28 *
     29 * @return void
     30 */
     31function sfabt_plugin_init() {
     32    // Nothing to do during autosave.
     33    if ( defined( 'DOING_AUTOSAVE' ) ) {
    5134        return;
    5235    }
    5336
    54     $done    = true;
    55     $user_id = get_current_user_id();
     37    $plugin_dir  = plugin_dir_path( __FILE__ );
     38    $plugin_name = 'SF Admin Bar Tools';
    5639
    57     include( SFABT_PLUGIN_DIR . 'inc/general.php' );
     40    // Check for WordPress and PHP version.
     41    require_once $plugin_dir . '/src/class-sfabt-requirements-check.php';
    5842
    59     // Check we have at least one coworker. If not, add the current user if eligible.
    60     if ( sfabt_is_eligible_user( $user_id ) && ! sfabt_coworkers_have_admin() && ! sfabt_is_coworker() ) {
    61         $options = sfabt_get_options();
    62         $options['coworkers'][] = $user_id;
    63         sfabt_update_options( $options );
    64     }
     43    $requirement_checks = new SFABT_Requirements_Check(
     44        array(
     45            'plugin_name'    => $plugin_name,
     46            'plugin_version' => SFABT_VERSION,
     47            'wp_version'     => '4.7',
     48            'php_version'    => '5.6',
     49        )
     50    );
    6551
    66     // Stop here for non-coworkers or if it's an ajjax call.
    67     if ( doing_ajax() || ! sfabt_is_coworker() ) {
     52    if ( ! $requirement_checks->check() ) {
     53        $requirement_checks->add_notice();
    6854        return;
    6955    }
    7056
    71     $show = sfabt_is_admin_bar_showing();
     57    // Init the plugin.
     58    require_once $plugin_dir . '/src/classes/Plugin.php';
    7259
    73     if ( $show ) {
    74         include( SFABT_PLUGIN_DIR . 'inc/adminbar-items.php' );
     60    $plugin = call_user_func(
     61        array( 'Screenfeed\AdminbarTools\Plugin', 'construct' ),
     62        array(
     63            'plugin_file' => __FILE__,
     64            'plugin_name' => $plugin_name,
     65        )
     66    );
     67
     68    $plugin->init();
     69}
     70
     71/**
     72 * Returns the user capacity required to operate the plugin.
     73 *
     74 * @since 4.0.0
     75 *
     76 * @return string A user capacity or user role.
     77 */
     78function sfabt_get_user_capacity() {
     79    static $cap;
     80
     81    if ( isset( $cap ) ) {
     82        return $cap;
    7583    }
    7684
    77     if ( is_admin() ) {
    78         include( SFABT_PLUGIN_DIR . 'inc/admin.php' );
     85    if ( defined( 'SFABT_CAP' ) && is_string( SFABT_CAP ) && '' !== SFABT_CAP ) {
     86        $cap = SFABT_CAP;
     87    } else {
     88        $cap = 'administrator';
     89    }
    7990
    80         if ( $show ) {
    81             include( SFABT_PLUGIN_DIR . 'inc/adminbar-items-admin.php' );
    82         }
    83 
    84         if ( 'profile.php' === $pagenow && defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) {
    85             include( SFABT_PLUGIN_DIR . 'inc/profile.php' );
    86         }
    87     } elseif ( is_frontend() && $show ) {
    88         include( SFABT_PLUGIN_DIR . 'inc/adminbar-items-frontend.php' );
    89     }
     91    return $cap;
    9092}
    9193
    92 
    93 /*------------------------------------------------------------------------------------------------*/
    94 /* !TOOLS ======================================================================================= */
    95 /*------------------------------------------------------------------------------------------------*/
    96 
    97 /*
    98  * A better <code>print_r()</code>, wrapped in a styled <code>&lt;pre&gt;</code> tag.
     94/**
     95 * Loads the plugin translations.
     96 * Previously named `sfabt_lang_init()`.
    9997 *
    100  * $var                     (mixed)    Variable to print out.
    101  * $display                 (bool|int) When false (default), print a "display: none" in the <code>&lt;pre&gt;</code> style. This way, you'll have to manually remove it (with firebug or any other tool), so you don't bother other users. But be aware that you can still break things.
    102  * $print_for_non_logged_in (bool|int) When false (default), nothing will be printed for logged out users.
    103  * ex:
    104  * pre_print_r($var)      : printed only for logged in users, but hidden for everybody (remove the display:hidden by yourself in the page).
    105  * pre_print_r($var, 1)   : printed only for logged in users, all logged in users can see the code.
    106  * pre_print_r($var, 0, 1): printed for everybody (logged out users too), but hidden for everybody (remove the display:hidden by yourself in the page).
    107  * pre_print_r($var, 1, 1): printed for everybody (logged out users too), all users can see the code.
     98 * @since 4.0.0
     99 *
     100 * @return void
    108101 */
    109 
    110 if ( ! function_exists( 'pre_print_r' ) ) :
    111     function pre_print_r( $var, $display = false, $print_for_non_logged_in = false ) {
    112         if ( ! $print_for_non_logged_in && ! ( function_exists( 'is_user_logged_in' ) && is_user_logged_in() ) ) {
    113             return;
    114         }
    115 
    116         echo '<pre style="background:rgb(34,34,34);line-height:19px;font-size:14px;color:#fff;text-shadow:none;font-family:monospace;padding:6px 10px;margin:2px;position:relative;z-index:10000;overflow:auto;' . ( (bool) $display ? '' : 'display:none;' ) . '">';
    117             if ( ( is_string( $var ) && '' === trim( $var ) ) || is_bool( $var ) || null === $var ) {
    118                 var_dump( $var );
    119             } else {
    120                 print_r( $var );
    121             }
    122             echo '<div style="clear:both"></div>';
    123         echo "</pre>\n";
    124     }
    125 endif;
     102function sfabt_load_translations() {
     103    load_plugin_textdomain( 'sf-adminbar-tools', false, basename( dirname( __FILE__ ) ) . '/languages/' );
     104}
  • sf-adminbar-tools/trunk/uninstall.php

    r1385704 r2458380  
    11<?php
    2 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
    3     exit();
    4 }
     2/**
     3 * What to do when the plugin is uninstalled.
     4 * php version 5.2
     5 *
     6 * @package Screenfeed/sf-adminbar-tools
     7 */
    58
     9defined( 'ABSPATH' ) || exit; // @phpstan-ignore-line
    610
    7 delete_option( 'sf-abt-open-files' );
    8 delete_option( '_sf_abt' );
    9 delete_metadata( 'user', 0, 'sf-abt-coworking', null, true );
    10 delete_metadata( 'user', 0, 'sf-abt-no-autosave', null, true );
    11 delete_metadata( 'user', 0, 'sf-abt-no-cowork-refresh', null, true );
     11delete_option( 'sfabt_settings' );
     12delete_site_option( 'sfabt_settings' );
     13delete_metadata( 'user', 0, 'sfabt-no-autosave', null, true );
Note: See TracChangeset for help on using the changeset viewer.