Exemplo n.º 1
0
 /**
  * View IP address rules.
  */
 public function status($args, $assoc_args)
 {
     $items = [];
     $labels = [esc_html__('IP Address', 'wprestcop'), esc_html__('Action', 'wprestcop'), esc_html__('Source', 'wprestcop')];
     $option = get_option('wprestcop_allowed_ips', []);
     $action_l10n = esc_html('ALLOW', 'wprestcop');
     foreach (wprestcop()->get_ip_rules()->get_allowed() as $ip) {
         $source = 'code';
         if (in_array($ip, $option)) {
             $source = 'option';
         }
         $items[] = array_combine($labels, [$ip, $action_l10n, $source]);
     }
     $option = get_option('wprestcop_denied_ips', []);
     $action_l10n = esc_html__('DENY', 'wprestcop');
     foreach (wprestcop()->get_ip_rules()->get_denied() as $ip) {
         $source = 'code';
         if (in_array($ip, $option)) {
             $source = 'option';
         }
         $items[] = array_combine($labels, [$ip, $action_l10n, $source]);
     }
     $format_args = [];
     $formatter = new WP_CLI\Formatter($format_args, $labels);
     $formatter->display_items($items);
 }
Exemplo n.º 2
0
/**
 * Retrieve the main plugin instance.
 *
 * @since 1.0.0
 *
 * @return \Cedaro\WPRESTCop\Plugin
 */
function wprestcop()
{
    static $instance;
    if (null === $instance) {
        $instance = new Plugin(new IPRules());
    }
    return $instance;
}
$wprestcop = wprestcop()->set_basename(plugin_basename(__FILE__))->set_directory(plugin_dir_path(__FILE__))->set_file(__FILE__)->set_slug('wprestcop')->set_url(plugin_dir_url(__FILE__));
/**
 * Register WP CLI commands.
 */
if (defined('WP_CLI') && WP_CLI) {
    include __DIR__ . '/php/CLI.php';
    $wprestcop->initialize_ip_rules();
    WP_CLI::add_command('restcop', '\\Cedaro\\WPRESTCop\\CLI');
}
/**
 * Localize the plugin.
 *
 * @since 1.0.0
 */
add_action('plugins_loaded', function () use($wprestcop) {
    $plugin_rel_path = dirname($wprestcop->get_basename()) . '/languages';