Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPCS fixes #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
}
],
"require": {
"php": ">=5.2"
"php": ">=5.2",
"10up/phpcs-composer": "dev-master"
},
"scripts": {
"lint": "phpcs dexter.php templates inc",
"lint-fix": "phpcbf dexter.php templates inc"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"require-dev": {
"wp-coding-standards/wpcs": "*",
"wimg/php-compatibility": "*",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4"
"phpcompatibility/phpcompatibility-wp": "^2.1"
}
}
338 changes: 261 additions & 77 deletions composer.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions dexter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@

namespace WpDexter;

/** Prevent direct access to the file **/
defined( 'ABSPATH' ) or die( 'Access denied' );
/**
* Prevent direct access to the file
**/
defined('ABSPATH') or die('Access denied');

define( 'WP_DEXTER_PATH', plugin_dir_path( __FILE__ ) );
define('WP_DEXTER_PATH', plugin_dir_path(__FILE__));

require_once( WP_DEXTER_PATH . '/inc/class-plugin.php' );
require_once WP_DEXTER_PATH . '/inc/class-plugin.php';

$plugin = Plugin::get_instance();
$plugin->init();
209 changes: 109 additions & 100 deletions inc/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,117 +10,126 @@
*
* @package WpDexter
*/
class Admin {
class Admin
{

/**
* Instance of the plugin.
*
* @var object
*/
public $plugin;
/**
* Instance of the plugin.
*
* @var object
*/
public $plugin;

/**
* Plugin slug.
*
* @var string
*/
const SLUG = 'wp-dexter';
/**
* Plugin slug.
*
* @var string
*/
const SLUG = 'wp-dexter';

/**
* The nonce name.
*
* @var string
*/
const NONCE_NAME = 'pokemon_generation_nonce';
/**
* The nonce name.
*
* @var string
*/
const NONCE_NAME = 'pokemon_generation_nonce';

/**
* The nonce action
*
* @var string
*/
const NONCE_ACTION = 'pokemon_generation_update';
/**
* The nonce action
*
* @var string
*/
const NONCE_ACTION = 'pokemon_generation_update';

/**
* Instantiate this class.
*
* @param object $plugin Instance of the plugin
*/
public function __construct( $plugin ) {
$this->plugin = $plugin;
}
/**
* Instantiate this class.
*
* @param object $plugin Instance of the plugin
*/
public function __construct( $plugin )
{
$this->plugin = $plugin;
}

/**
* Plugin admin page initializer.
*/
public function init() {
add_action( 'admin_menu', array( $this, 'admin_menus' ) );
add_action( 'admin_post_wp-dexter-save', array( $this, 'save' ) );
add_action( 'admin_head', array( $this, 'add_styles' ) );
add_action( 'init', array( $this, 'textdomain' ) );
}
/**
* Plugin admin page initializer.
*/
public function init()
{
add_action('admin_menu', array( $this, 'admin_menus' ));
add_action('admin_post_wp-dexter-save', array( $this, 'save' ));
add_action('admin_head', array( $this, 'add_styles' ));
add_action('init', array( $this, 'textdomain' ));
}

/**
* Loads the plugin Text Domain. Enables plugin translation.
*/
public function textdomain() {
load_plugin_textdomain( self::SLUG );
}
/**
* Loads the plugin Text Domain. Enables plugin translation.
*/
public function textdomain()
{
load_plugin_textdomain(self::SLUG);
}

/**
* Creates the plugin's settings page in the settings menu.
*/
public function admin_menus() {
add_options_page(
__( 'WP-Dexter', 'wp-dexter' ),
__( 'WP-Dexter', 'wp-dexter' ),
'manage_options',
'wp-dexter',
array( $this, 'render_options_page' )
);
}
/**
* Creates the plugin's settings page in the settings menu.
*/
public function admin_menus()
{
add_options_page(
__('WP-Dexter', 'wp-dexter'),
__('WP-Dexter', 'wp-dexter'),
'manage_options',
'wp-dexter',
array( $this, 'render_options_page' )
);
}

/**
* Enqueues the CSS stylesheet.
*/
public function add_styles() {
if ( $this->is_dexter_settings_page() ) {
wp_enqueue_style( 'dexter_backend_css', plugins_url( '../dist/css/frontend.css', __FILE__ ), array(), Plugin::VERSION );
}
}
/**
* Enqueues the CSS stylesheet.
*/
public function add_styles()
{
if ($this->is_dexter_settings_page() ) {
wp_enqueue_style('dexter_backend_css', plugins_url('../dist/css/frontend.css', __FILE__), array(), Plugin::VERSION);
}
}

/**
* Renders the main page.
*/
public function render_options_page() {
include( dirname( __FILE__ ) . '/../templates/settings-page.php' );
}
/**
* Renders the main page.
*/
public function render_options_page()
{
include dirname(__FILE__) . '/../templates/settings-page.php';
}

/**
* Checks if this is Dexter settings page.
*
* @return bool
*/
public function is_dexter_settings_page() {
if ( 'settings_page_wp-dexter' === get_current_screen()->id ) {
return true;
}
return false;
}
/**
* Checks if this is Dexter settings page.
*
* @return bool
*/
public function is_dexter_settings_page()
{
if ('settings_page_wp-dexter' === get_current_screen()->id ) {
return true;
}
return false;
}

/**
* Process and saves the form settings.
*/
public function save() {
$verify = (
isset( $_POST['pokemon_generation'], $_POST[ self::NONCE_NAME ] )
&&
wp_verify_nonce( sanitize_key( wp_unslash( $_POST[ self::NONCE_NAME ] ) ), self::NONCE_ACTION )
);
/**
* Process and saves the form settings.
*/
public function save()
{
$verify = (
isset($_POST['pokemon_generation'], $_POST[ self::NONCE_NAME ])
&&
wp_verify_nonce(sanitize_key(wp_unslash($_POST[ self::NONCE_NAME ])), self::NONCE_ACTION)
);

if ( true === $verify ) {
update_option( 'wp_dexter_pokemon_generation', sanitize_text_field( wp_unslash( $_POST['pokemon_generation'] ) ) );
wp_redirect( admin_url( 'options-general.php?page=wp-dexter' ) . '&updated=true' );
exit;
}
}
if (true === $verify ) {
update_option('wp_dexter_pokemon_generation', sanitize_text_field(wp_unslash($_POST['pokemon_generation'])));
wp_redirect(admin_url('options-general.php?page=wp-dexter') . '&updated=true');
exit;
}
}
}
Loading