diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..1b0614d --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,22 @@ +version: 2.1 + +jobs: + test: + docker: + - image: circleci/php:7.3.3-stretch-node-browsers + steps: + - checkout + - prepare-environment + - run: composer phpcs + +commands: + prepare-environment: + description: "Install dependencies." + steps: + - run: composer install + +workflows: + version: 2 + check-wp-cs: + jobs: + - test diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9cef246 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +# WordPress Coding Standards +# http://make.wordpress.org/core/handbook/coding-standards/ + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = tab + +[*.yml] +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore index 54c0329..1086bf3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .DS_Store Thumbs.db .svn -node_modules/ \ No newline at end of file +node_modules/ +vendor/ +*.swp diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..1860a64 --- /dev/null +++ b/composer.json @@ -0,0 +1,32 @@ +{ + "name": "studiopress/genesis-simple-sidebars", + "type": "wordpress-plugin", + "description": "Genesis Simple Sidebars allows you to easily create and use new sidebar widget areas.", + "homepage": "https://github.com/studiopress/genesis-simple-sidebars", + "license": "GPL-2.0-or-later", + "require": { + "php": "^5.3 || ^7", + "composer/installers": "^1" + }, + "require-dev": { + "php": "^5.6 || ^7", + "dealerdirect/phpcodesniffer-composer-installer": "*", + "squizlabs/php_codesniffer": "^3.3.1", + "phpcompatibility/phpcompatibility-wp": "*", + "wp-coding-standards/wpcs": "^1" + }, + "config": { + "sort-order": true + }, + "minimum-stability": "dev", + "prefer-stable": true, + "scripts": { + "phpcs": "phpcs --standard=WordPress --ignore=vendor/,node_modules/,assets/ --extensions=php -p ./", + "phpcs-compat": "phpcs --extensions=php --standard=PHPCompatibilityWP --ignore=vendor/,node_modules/,assets/ --runtime-set testVersion 5.6- -p ./", + "phpcbf": "phpcbf --standard=WordPress --ignore=vendor/,node_modules/,assets/ --extensions=php -p ./" + }, + "support": { + "issues": "https://github.com/studiopress/genesis-simple-sidebars/issues", + "source": "https://github.com/studiopress/genesis-simple-sidebars" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..75312a6 --- /dev/null +++ b/composer.lock @@ -0,0 +1,461 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "a8300ed9bb532b9d84d4cb8a37879f11", + "packages": [ + { + "name": "composer/installers", + "version": "v1.6.0", + "source": { + "type": "git", + "url": "https://github.com/composer/installers.git", + "reference": "cfcca6b1b60bc4974324efb5783c13dca6932b5b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/installers/zipball/cfcca6b1b60bc4974324efb5783c13dca6932b5b", + "reference": "cfcca6b1b60bc4974324efb5783c13dca6932b5b", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0" + }, + "replace": { + "roundcube/plugin-installer": "*", + "shama/baton": "*" + }, + "require-dev": { + "composer/composer": "1.0.*@dev", + "phpunit/phpunit": "^4.8.36" + }, + "type": "composer-plugin", + "extra": { + "class": "Composer\\Installers\\Plugin", + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Installers\\": "src/Composer/Installers" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kyle Robinson Young", + "email": "kyle@dontkry.com", + "homepage": "https://github.com/shama" + } + ], + "description": "A multi-framework Composer library installer", + "homepage": "https://composer.github.io/installers/", + "keywords": [ + "Craft", + "Dolibarr", + "Eliasis", + "Hurad", + "ImageCMS", + "Kanboard", + "Lan Management System", + "MODX Evo", + "Mautic", + "Maya", + "OXID", + "Plentymarkets", + "Porto", + "RadPHP", + "SMF", + "Thelia", + "WolfCMS", + "agl", + "aimeos", + "annotatecms", + "attogram", + "bitrix", + "cakephp", + "chef", + "cockpit", + "codeigniter", + "concrete5", + "croogo", + "dokuwiki", + "drupal", + "eZ Platform", + "elgg", + "expressionengine", + "fuelphp", + "grav", + "installer", + "itop", + "joomla", + "kohana", + "laravel", + "lavalite", + "lithium", + "magento", + "majima", + "mako", + "mediawiki", + "modulework", + "modx", + "moodle", + "osclass", + "phpbb", + "piwik", + "ppi", + "puppet", + "pxcms", + "reindex", + "roundcube", + "shopware", + "silverstripe", + "sydes", + "symfony", + "typo3", + "wordpress", + "yawik", + "zend", + "zikula" + ], + "time": "2018-08-27T06:10:37+00:00" + } + ], + "packages-dev": [ + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.5.0", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "e749410375ff6fb7a040a68878c656c2e610b132" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/e749410375ff6fb7a040a68878c656c2e610b132", + "reference": "e749410375ff6fb7a040a68878c656c2e610b132", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0", + "php": "^5.3|^7", + "squizlabs/php_codesniffer": "^2|^3" + }, + "require-dev": { + "composer/composer": "*", + "phpcompatibility/php-compatibility": "^9.0", + "sensiolabs/security-checker": "^4.1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "time": "2018-10-26T13:21:45+00:00" + }, + { + "name": "phpcompatibility/php-compatibility", + "version": "9.1.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", + "reference": "2b63c5d284ab8857f7b1d5c240ddb507a6b2293c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/2b63c5d284ab8857f7b1d5c240ddb507a6b2293c", + "reference": "2b63c5d284ab8857f7b1d5c240ddb507a6b2293c", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.3 || ^3.0.2" + }, + "conflict": { + "squizlabs/php_codesniffer": "2.6.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" + }, + { + "name": "Wim Godden", + "homepage": "https://github.com/wimg", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + } + ], + "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", + "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", + "keywords": [ + "compatibility", + "phpcs", + "standards" + ], + "time": "2018-12-30T23:16:27+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-paragonie", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", + "reference": "9160de79fcd683b5c99e9c4133728d91529753ea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/9160de79fcd683b5c99e9c4133728d91529753ea", + "reference": "9160de79fcd683b5c99e9c4133728d91529753ea", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "paragonie", + "phpcs", + "polyfill", + "standards" + ], + "time": "2018-12-16T19:10:44+00:00" + }, + { + "name": "phpcompatibility/phpcompatibility-wp", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", + "reference": "cb303f0067cd5b366a41d4fb0e254fb40ff02efd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/cb303f0067cd5b366a41d4fb0e254fb40ff02efd", + "reference": "cb303f0067cd5b366a41d4fb0e254fb40ff02efd", + "shasum": "" + }, + "require": { + "phpcompatibility/php-compatibility": "^9.0", + "phpcompatibility/phpcompatibility-paragonie": "^1.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "lead" + } + ], + "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.", + "homepage": "http://phpcompatibility.com/", + "keywords": [ + "compatibility", + "phpcs", + "standards", + "wordpress" + ], + "time": "2018-10-07T18:31:37+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.4.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8", + "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2019-04-10T23:49:02+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git", + "reference": "f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c", + "reference": "f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.9.0 || ^3.0.2" + }, + "require-dev": { + "phpcompatibility/php-compatibility": "^9.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "wordpress" + ], + "time": "2018-12-18T09:43:51+00:00" + } + ], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": true, + "prefer-lowest": false, + "platform": { + "php": "^5.3 || ^7" + }, + "platform-dev": { + "php": "^5.6 || ^7" + } +} diff --git a/genesis-simple-sidebars.php b/genesis-simple-sidebars.php index 962ba45..b0c7927 100644 --- a/genesis-simple-sidebars.php +++ b/genesis-simple-sidebars.php @@ -1,190 +1,43 @@ plugin_dir_url = plugin_dir_url( __FILE__ ); - $this->plugin_dir_path = plugin_dir_path( __FILE__ ); - - // For backward compatibility - define( 'SS_PLUGIN_DIR', $this->plugin_dir_path ); - - } - - /** - * Initialize. - * - * @since 2.1.0 - */ - public function init() { - - $this->load_plugin_textdomain(); - - add_action( 'admin_notices', array( $this, 'requirements_notice' ) ); - - $this->includes(); - $this->instantiate(); - - } - - /** - * Show admin notice if minimum requirements aren't met. - * - * @since 2.1.0 - */ - public function requirements_notice() { - - if ( ! defined( 'PARENT_THEME_VERSION' ) || ! version_compare( PARENT_THEME_VERSION, $this->min_genesis_version, '>=' ) ) { - - $action = defined( 'PARENT_THEME_VERSION' ) ? __( 'upgrade to', 'genesis-simple-sidebars' ) : __( 'install and activate', 'genesis-simple-sidebars' ); - - $message = sprintf( __( 'Genesis Simple Sidebars requires WordPress %s and Genesis %s, or greater. Please %s the latest version of Genesis to use this plugin.', 'genesis-simple-sidebars' ), $this->min_wp_version, $this->min_genesis_version, $action, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa' ); - echo '

' . $message . '

'; - - } - - } - - /** - * Load the plugin textdomain, for translation. - * - * @since 2.1.0 - */ - public function load_plugin_textdomain() { - load_plugin_textdomain( $this->plugin_textdomain, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); - } - - /** - * All general includes. - * - * @since 2.1.0 - */ - public function includes() { - - require_once( $this->plugin_dir_path . 'includes/functions.php' ); - require_once( $this->plugin_dir_path . 'includes/deprecated.php' ); - - } - - /** - * Include the class file, instantiate the classes, create objects. - * - * @since 2.1.0 - */ - public function instantiate() { - - add_action( 'genesis_setup', array( $this, 'genesis_dependencies' ) ); - - } - - /** - * Load and instantiate any Genesis dependencies. - * - * @since 2.1.0 - */ - public function genesis_dependencies() { - - require_once( $this->plugin_dir_path . 'includes/class-genesis-simple-sidebars-core.php' ); - $this->core = new Genesis_Simple_Sidebars_Core; - $this->core->init(); - - // Anything beyond this point should only be loaded if in the admin. - if ( ! is_admin() ) { - return; - } - - require_once( $this->plugin_dir_path . 'includes/class-genesis-simple-sidebars-entry.php' ); - $this->entry = new Genesis_Simple_Sidebars_Entry; - $this->entry->init(); - - require_once( $this->plugin_dir_path . 'includes/class-genesis-simple-sidebars-term.php' ); - $this->term = new Genesis_Simple_Sidebars_Term; - $this->term->init(); - - require_once( $this->plugin_dir_path . 'includes/class-genesis-simple-sidebars-admin.php' ); - $this->admin = new Genesis_Simple_Sidebars_Admin; - $this->admin->admin_menu(); - - // For backward compatibility - global $_genesis_simple_sidebars; - $_genesis_simple_sidebars = $this->admin; - - } +/** + * Load the plugin file. + */ +if ( ! defined( 'ABSPATH' ) ) { + exit; } +define( 'GENESIS_SIMPLE_SIDEBARS_SETTINGS_FIELD', 'genesis_simple_sidebars_settings' ); +define( 'GENESIS_SIMPLE_SIDEBARS_VERSION', '2.2.0' ); +define( 'GENESIS_SIMPLE_SIDEBARS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); +define( 'GENESIS_SIMPLE_SIDEBARS_PLUGIN_URL', plugins_url( '', __FILE__ ) ); + +require_once plugin_dir_path( __FILE__ ) . 'includes/class-genesis-simple-sidebars.php'; + + + /** * Helper function to retrieve the static object without using globals. * * @since 2.1.0 */ -function Genesis_Simple_Sidebars() { +function genesis_simple_sidebars() { static $object; - if ( null == $object ) { - $object = new Genesis_Simple_Sidebars; + if ( null === $object ) { + $object = new Genesis_Simple_Sidebars(); } return $object; } /** - * Initialize the object on `plugins_loaded`. + * Initialize the object on `plugins_loaded`. */ add_action( 'plugins_loaded', array( Genesis_Simple_Sidebars(), 'init' ) ); diff --git a/includes/class-genesis-simple-sidebars-admin.php b/includes/class-genesis-simple-sidebars-admin.php index d2a572a..8f6f236 100644 --- a/includes/class-genesis-simple-sidebars-admin.php +++ b/includes/class-genesis-simple-sidebars-admin.php @@ -3,6 +3,7 @@ * Controls the creation, deletion, and editing of Simple Sidebar. * * @author StudioPress + * @package genesis-simple-sidebars */ /** @@ -16,6 +17,8 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic { /** * Settings field. * + * @var string + * * @since 2.1.0 */ public $settings_field; @@ -27,7 +30,7 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic { $this->settings_field = Genesis_Simple_Sidebars()->settings_field; - // For backward compatibility + // For backward compatibility. define( 'SS_SETTINGS_FIELD', $this->settings_field ); } @@ -49,16 +52,16 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic { 'submenu' => array( 'parent_slug' => 'genesis', 'page_title' => __( 'Genesis - Simple Sidebars', 'genesis-simple-sidebars' ), - 'menu_title' => __( 'Simple Sidebars', 'genesis-simple-sidebars' ) - ) + 'menu_title' => __( 'Simple Sidebars', 'genesis-simple-sidebars' ), + ), ); - // Empty, as we'll be building the page manually + // Empty, as we'll be building the page manually. $page_ops = array(); $this->create( $page_id, $menu_ops, $page_ops, $this->settings_field ); - // Simpe Sidebar actions (create, edit, or delete) + // Simpe Sidebar actions (create, edit, or delete). add_action( 'admin_init', array( $this, 'actions' ) ); } @@ -69,18 +72,17 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic { * Echoes out HTML. * * @since 1.0.0 - * */ public function admin() { echo '
'; - if ( isset( $_REQUEST['action'] ) && 'edit' == $_REQUEST['action'] ) { - require_once( Genesis_Simple_Sidebars()->plugin_dir_path . '/includes/views/admin-edit.php' ); - } - else { - require_once( Genesis_Simple_Sidebars()->plugin_dir_path . '/includes/views/admin-main.php' ); - } + // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification + if ( isset( $_REQUEST['action'] ) && 'edit' === $_REQUEST['action'] ) { + require_once GENESIS_SIMPLE_SIDEBARS_PLUGIN_DIR . '/includes/views/admin-edit.php'; + } else { + require_once GENESIS_SIMPLE_SIDEBARS_PLUGIN_DIR . '/includes/views/admin-main.php'; + } echo '
'; @@ -92,7 +94,6 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic { * Displays table rows of sidebars for viewing and editing on the main admin page. * * @since 1.0.0 - * */ public function table_rows() { @@ -106,32 +107,40 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic { $is_editable = isset( $info['editable'] ) && $info['editable'] ? true : false; - ?> + ?> - > + + > %s', admin_url('admin.php?page=simple-sidebars&action=edit&id=' . esc_html( $id ) ), esc_html( $info['name'] ), esc_html( $info['name'] ) ); - } else { - printf( '%s', esc_html( $info['name'] ) ); - } + if ( $is_editable ) { + printf( '%s', esc_url( admin_url( 'admin.php?page=simple-sidebars&action=edit&id=' . esc_html( $id ) ) ), esc_html( $info['name'] ), esc_html( $info['name'] ) ); + } else { + printf( '%s', esc_html( $info['name'] ) ); + } ?>
- | - + | +
- + - create_sidebar( $_POST['new_sidebar'] ); + // phpcs:disable WordPress.Security.NonceVerification.NoNonceVerification + if ( isset( $_REQUEST['action'] ) && 'create' === $_REQUEST['action'] && isset( $_POST['new_sidebar'] ) ) { + $this->create_sidebar( array_map( 'sanitize_text_field', wp_unslash( $_POST['new_sidebar'] ) ) ); } /** * This section will handle the data if a sidebar is deleted */ - if ( isset( $_REQUEST['action'] ) && 'delete' == $_REQUEST['action'] && isset( $_REQUEST['id'] ) ) { - $this->delete_sidebar( $_REQUEST['id'] ); + // phpcs:disable WordPress.Security.NonceVerification.NoNonceVerification + if ( isset( $_REQUEST['action'] ) && 'delete' === $_REQUEST['action'] && isset( $_REQUEST['id'] ) ) { + $this->delete_sidebar( sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) ); } /** * This section will handle the data if a sidebar is to be modified */ - if ( isset( $_REQUEST['action'] ) && 'edit' == $_REQUEST['action'] && ! isset( $_REQUEST['id'] ) ) { - $this->edit_sidebar( $_POST['edit_sidebar'] ); + if ( isset( $_REQUEST['action'] ) && 'edit' === $_REQUEST['action'] && ! isset( $_REQUEST['id'] ) && isset( $_POST['edit_sidebar'] ) ) { + $this->edit_sidebar( array_map( 'sanitize_text_field', wp_unslash( $_POST['edit_sidebar'] ) ) ); } - + // phpcs:enable } /** @@ -188,39 +198,38 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic { $pattern = '

%s

'; + // phpcs:disable WordPress.Security.NonceVerification.NoNonceVerification if ( isset( $_REQUEST['created'] ) && 'true' === $_REQUEST['created'] ) { - printf( $pattern, __( 'New sidebar successfully created!', 'genesis-simple-sidebars' ) ); + printf( wp_kses_post( $pattern ), esc_html__( 'New sidebar successfully created!', 'genesis-simple-sidebars' ) ); return; } if ( isset( $_REQUEST['edited'] ) && 'true' === $_REQUEST['edited'] ) { - printf( $pattern, __( 'Sidebar successfully edited!', 'genesis-simple-sidebars' ) ); + printf( wp_kses_post( $pattern ), esc_html__( 'Sidebar successfully edited!', 'genesis-simple-sidebars' ) ); return; } if ( isset( $_REQUEST['deleted'] ) && 'true' === $_REQUEST['deleted'] ) { - printf( $pattern, __( 'Sidebar successfully deleted.', 'genesis-simple-sidebars' ) ); + printf( wp_kses_post( $pattern ), esc_html__( 'Sidebar successfully deleted.', 'genesis-simple-sidebars' ) ); return; } - return; - } /** * Create a sidebar. * - * @since 1.0.0 + * @param array $args Arguments. * + * @since 1.0.0 */ protected function create_sidebar( $args = array() ) { - if ( empty( $args['name'] ) ) { - wp_die( $this->error( 1 ) ); + wp_die( esc_html( $this->error( 1 ) ) ); exit; } - // nonce verification + // nonce verification. check_admin_referer( 'simple-sidebars-action_create-sidebar' ); $db = (array) get_option( $this->settings_field ); @@ -231,7 +240,7 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic { } // Strip all but alphanumeric, sanitize with dashes. - $id = preg_replace( "/[^a-zA-Z0-9 -]+/", "", sanitize_title_with_dashes( $args['id'] ) ); + $id = preg_replace( '/[^a-zA-Z0-9 -]+/', '', sanitize_title_with_dashes( $args['id'] ) ); // Preface numeric IDs with 'sidebar-'. $id = is_numeric( $id ) ? 'gss-sidebar-' . $id : $id; @@ -240,26 +249,27 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic { if ( ! $id || is_registered_sidebar( $id ) ) { $n = count( $db ) + 1; do { - $id = 'gss-sidebar-' . $n++; + $n = $n++; + $id = 'gss-sidebar-' . $n; } while ( is_registered_sidebar( $id ) ); } $new = array( $id => array( 'name' => esc_html( $args['name'] ), - 'description' => esc_html( $args['description'] ) + 'description' => esc_html( $args['description'] ), ), ); if ( array_key_exists( $id, $db ) ) { - wp_die( $this->error( 2 ) ); + wp_die( esc_html( $this->error( 2 ) ) ); exit; } $_sidebars = wp_parse_args( $new, $db ); update_option( $this->settings_field, $_sidebars ); - wp_redirect( admin_url( 'admin.php?page=simple-sidebars&created=true' ) ); + wp_safe_redirect( admin_url( 'admin.php?page=simple-sidebars&created=true' ) ); exit; } @@ -267,36 +277,36 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic { /** * Edit a sidebar. * + * @param array $args Arguments. * @since 1.0.0 - * */ protected function edit_sidebar( $args = array() ) { if ( empty( $args['name'] ) || empty( $args['id'] ) ) { - wp_die( $this->error( 3 ) ); + wp_die( esc_html( $this->error( 3 ) ) ); exit; } - // nonce verification + // nonce verification. check_admin_referer( 'simple-sidebars-action_edit-sidebar' ); - $db = (array) get_option( $this->settings_field ); + $db = (array) get_option( $this->settings_field ); $new = array( $args['id'] => array( 'name' => esc_html( $args['name'] ), - 'description' => esc_html( $args['description'] ) - ) + 'description' => esc_html( $args['description'] ), + ), ); if ( ! array_key_exists( $args['id'], $db ) ) { - wp_die( $this->error( 3 ) ); + wp_die( esc_html( $this->error( 3 ) ) ); exit; } $_sidebars = wp_parse_args( $new, $db ); update_option( $this->settings_field, $_sidebars ); - wp_redirect( admin_url( 'admin.php?page=simple-sidebars&edited=true' ) ); + wp_safe_redirect( admin_url( 'admin.php?page=simple-sidebars&edited=true' ) ); exit; } @@ -304,30 +314,29 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic { /** * Delete a sidebar. * + * @param string $id Id. * @since 1.0.0 - * */ protected function delete_sidebar( $id = '' ) { - if ( empty( $id ) ) { - wp_die( $this->error( 4 ) ); + wp_die( esc_html( $this->error( 4 ) ) ); exit; } - // nonce verification + // nonce verification. check_admin_referer( 'simple-sidebars-action_delete-sidebar' ); $_sidebars = (array) get_option( $this->settings_field ); - if ( ! isset( $_sidebars[$id] ) ) { - wp_die( $this->error( 4 ) ); + if ( ! isset( $_sidebars[ $id ] ) ) { + wp_die( esc_html( $this->error( 4 ) ) ); exit; } - unset( $_sidebars[$id] ); + unset( $_sidebars[ $id ] ); update_option( $this->settings_field, $_sidebars ); - wp_redirect( admin_url( 'admin.php?page=simple-sidebars&deleted=true' ) ); + wp_safe_redirect( admin_url( 'admin.php?page=simple-sidebars&deleted=true' ) ); exit; } @@ -335,29 +344,28 @@ class Genesis_Simple_Sidebars_Admin extends Genesis_Admin_Basic { /** * Returns an error message by ID. * + * @param bool $error Error id. + * * @since 1.0.0 * * @return string Returns an error string based on an error ID. */ protected function error( $error = false ) { - if ( ! $error ) + if ( ! $error ) { return false; + } - switch( (int) $error ) { + switch ( (int) $error ) { case 1: return __( 'Oops! Please choose a valid Name for this sidebar', 'genesis-simple-sidebars' ); - break; case 2: return __( 'Oops! That sidebar ID already exists', 'genesis-simple-sidebars' ); - break; case 3: return __( 'Oops! You are trying to edit a sidebar that does not exist, or is not editable', 'genesis-simple-sidebars' ); - break; case 4: return __( 'Oops! You are trying to delete a sidebar that does not exist, or cannot be deleted', 'genesis-simple-sidebars' ); - break; default: return __( 'Oops! Something went wrong. Try again.', 'genesis-simple-sidebars' ); diff --git a/includes/class-genesis-simple-sidebars-core.php b/includes/class-genesis-simple-sidebars-core.php index 72766b9..74eef80 100644 --- a/includes/class-genesis-simple-sidebars-core.php +++ b/includes/class-genesis-simple-sidebars-core.php @@ -1,4 +1,9 @@ $info ) { if ( ! isset( $info['name'] ) || ! isset( $info['description'] ) ) { continue; } - genesis_register_sidebar( array( - 'name' => esc_html( $info['name'] ), - 'id' => $id, - 'description' => esc_html( $info['description'] ), - 'editable' => 1, - ) ); + genesis_register_sidebar( + array( + 'name' => esc_html( $info['name'] ), + 'id' => $id, + 'description' => esc_html( $info['description'] ), + 'editable' => 1, + ) + ); } @@ -71,6 +87,8 @@ class Genesis_Simple_Sidebars_Core { /** * Filter the widgets in each widget area. * + * @param array $widgets Widgets. + * * @since 2.1.0 */ public function sidebars_widgets_filter( $widgets ) { @@ -106,6 +124,9 @@ class Genesis_Simple_Sidebars_Core { /** * Take the $widgets array and swap the contents of each widget area with a custom widget area, if specified. * + * @param array $widgets Widgets. + * @param array $sidebars Sidebars. + * * @since 2.1.0 */ public function swap_widgets( $widgets, $sidebars ) { @@ -123,7 +144,6 @@ class Genesis_Simple_Sidebars_Core { if ( $new_sidebar && ! empty( $widgets[ $new_sidebar ] ) ) { $widgets[ $old_sidebar ] = $widgets[ $new_sidebar ]; } - } return $widgets; @@ -133,6 +153,8 @@ class Genesis_Simple_Sidebars_Core { /** * Get all custom registered sidebars. * + * @param bool $cache Indicates if should get from cache. + * * @since 2.1.0 */ public function get_sidebars( $cache = true ) { @@ -159,10 +181,12 @@ class Genesis_Simple_Sidebars_Core { public function get_public_taxonomies() { if ( is_null( $this->public_taxonomies ) ) { - $this->public_taxonomies = get_taxonomies( array( - 'show_ui' => true, - 'public' => true, - ) ); + $this->public_taxonomies = get_taxonomies( + array( + 'show_ui' => true, + 'public' => true, + ) + ); } $this->public_taxonomies = apply_filters( 'genesis_simple_sidebars_taxonomies', array_keys( $this->public_taxonomies ) ); diff --git a/includes/class-genesis-simple-sidebars-entry.php b/includes/class-genesis-simple-sidebars-entry.php index f89c8b5..60279d7 100644 --- a/includes/class-genesis-simple-sidebars-entry.php +++ b/includes/class-genesis-simple-sidebars-entry.php @@ -1,7 +1,18 @@ true ) ) as $type ) { - if ( post_type_supports( $type, 'genesis-simple-sidebars' ) || $type == 'post' || $type == 'page' ) { + if ( post_type_supports( $type, 'genesis-simple-sidebars' ) || 'post' === $type || 'page' === $type ) { add_meta_box( 'ss_inpost_metabox', __( 'Sidebar Selection', 'genesis-simple-sidebars' ), array( $this, 'metabox_content' ), $type, 'side', 'low' ); } - } } @@ -33,26 +43,34 @@ class Genesis_Simple_Sidebars_Entry { */ public function metabox_content() { - require_once( Genesis_Simple_Sidebars()->plugin_dir_path . 'includes/views/entry-metabox-content.php' ); + require_once GENESIS_SIMPLE_SIDEBARS_PLUGIN_DIR . '/includes/views/entry-metabox-content.php'; } /** * Save the metabox fields when the entry is saved. * + * @param string $post_id Post Id. + * @param array $post Post. * @since 2.1.0 */ public function metabox_save( $post_id, $post ) { - if ( ! isset( $_POST['genesis_simple_sidebars'] ) ) { + // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification + $genesis_simple_sidebars = isset( $_POST['genesis_simple_sidebars'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['genesis_simple_sidebars'] ) ) : ''; + + if ( empty( $genesis_simple_sidebars ) ) { return; } - $data = wp_parse_args( $_POST['genesis_simple_sidebars'], array( - '_ss_header' => '', - '_ss_sidebar' => '', - '_ss_sidebar_alt' => '', - ) ); + $data = wp_parse_args( + $genesis_simple_sidebars, + array( + '_ss_header' => '', + '_ss_sidebar' => '', + '_ss_sidebar_alt' => '', + ) + ); genesis_save_custom_fields( $data, 'genesis-simple-sidebars-save-entry', 'genesis-simple-sidebars-save-entry-nonce', $post ); diff --git a/includes/class-genesis-simple-sidebars-term.php b/includes/class-genesis-simple-sidebars-term.php index af9f64b..5686a5e 100644 --- a/includes/class-genesis-simple-sidebars-term.php +++ b/includes/class-genesis-simple-sidebars-term.php @@ -1,13 +1,27 @@ core->get_public_taxonomies(); @@ -17,14 +31,19 @@ class Genesis_Simple_Sidebars_Term { foreach ( $taxonomies as $tax ) { add_action( "{$tax}_edit_form", array( $this, 'term_sidebar_form' ), 9, 2 ); } - } } + /** + * Import the sidebar form. + * + * @param string $tag Tag. + * @param string $taxonomy Taxonomy. + */ public function term_sidebar_form( $tag, $taxonomy ) { - require_once( Genesis_Simple_Sidebars()->plugin_dir_path . 'includes/views/term-edit-sidebar-form.php' ); + require_once GENESIS_SIMPLE_SIDEBARS_PLUGIN_DIR . '/includes/views/term-edit-sidebar-form.php'; } diff --git a/includes/class-genesis-simple-sidebars.php b/includes/class-genesis-simple-sidebars.php new file mode 100644 index 0000000..ff58ac0 --- /dev/null +++ b/includes/class-genesis-simple-sidebars.php @@ -0,0 +1,175 @@ +load_plugin_textdomain(); + + add_action( 'admin_notices', array( $this, 'requirements_notice' ) ); + + $this->includes(); + $this->instantiate(); + + } + + /** + * Show admin notice if minimum requirements aren't met. + * + * @since 2.1.0 + */ + public function requirements_notice() { + + if ( ! defined( 'PARENT_THEME_VERSION' ) || ! version_compare( PARENT_THEME_VERSION, $this->min_genesis_version, '>=' ) ) { + + $action = defined( 'PARENT_THEME_VERSION' ) ? __( 'upgrade to', 'genesis-simple-sidebars' ) : __( 'install and activate', 'genesis-simple-sidebars' ); + + // translators: %1$s is WordPress minimum version, %2$s is Genesis minimum version, %3$s is action and %4$s is link. + $message = sprintf( __( 'Genesis Simple Sidebars requires WordPress %1$s and Genesis %2$s, or greater. Please %3$s the latest version of Genesis to use this plugin.', 'genesis-simple-sidebars' ), $this->min_wp_version, $this->min_genesis_version, $action, 'http://my.studiopress.com/?download_id=91046d629e74d525b3f2978e404e7ffa' ); + echo '

' . esc_html( $message ) . '

'; + + } + + } + + /** + * Load the plugin textdomain, for translation. + * + * @since 2.1.0 + */ + public function load_plugin_textdomain() { + load_plugin_textdomain( $this->plugin_textdomain, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); + } + + /** + * All general includes. + * + * @since 2.1.0 + */ + public function includes() { + + require_once GENESIS_SIMPLE_SIDEBARS_PLUGIN_DIR . '/includes/functions.php'; + require_once GENESIS_SIMPLE_SIDEBARS_PLUGIN_DIR . '/includes/deprecated.php'; + + } + + /** + * Include the class file, instantiate the classes, create objects. + * + * @since 2.1.0 + */ + public function instantiate() { + + add_action( 'genesis_setup', array( $this, 'genesis_dependencies' ) ); + + } + + /** + * Load and instantiate any Genesis dependencies. + * + * @since 2.1.0 + */ + public function genesis_dependencies() { + + require_once GENESIS_SIMPLE_SIDEBARS_PLUGIN_DIR . '/includes/class-genesis-simple-sidebars-core.php'; + $this->core = new Genesis_Simple_Sidebars_Core(); + $this->core->init(); + + // Anything beyond this point should only be loaded if in the admin. + if ( ! is_admin() ) { + return; + } + + require_once GENESIS_SIMPLE_SIDEBARS_PLUGIN_DIR . '/includes/class-genesis-simple-sidebars-entry.php'; + $this->entry = new Genesis_Simple_Sidebars_Entry(); + $this->entry->init(); + + require_once GENESIS_SIMPLE_SIDEBARS_PLUGIN_DIR . '/includes/class-genesis-simple-sidebars-term.php'; + $this->term = new Genesis_Simple_Sidebars_Term(); + $this->term->init(); + + require_once GENESIS_SIMPLE_SIDEBARS_PLUGIN_DIR . '/includes/class-genesis-simple-sidebars-admin.php'; + $this->admin = new Genesis_Simple_Sidebars_Admin(); + $this->admin->admin_menu(); + + // For backward compatibility. + global $_genesis_simple_sidebars; + $_genesis_simple_sidebars = $this->admin; + + } + +} diff --git a/includes/deprecated.php b/includes/deprecated.php index ae3aedc..559f8ff 100644 --- a/includes/deprecated.php +++ b/includes/deprecated.php @@ -1,4 +1,9 @@ core->get_sidebars(); -if ( array_key_exists( $_REQUEST['id'], (array) $sidebars ) ) { - $sidebar = stripslashes_deep( $sidebars[ $_REQUEST['id'] ] ); +// phpcs:disable WordPress.Security.NonceVerification.NoNonceVerification +if ( isset( $_REQUEST['id'] ) && array_key_exists( sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ), (array) $sidebars ) ) { + $sidebar = stripslashes_deep( $sidebars[ sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ) ] ); } else { - wp_die( __( 'Nice try, partner. But that sidebar doesn\'t exist. Click back and try again.', 'genesis-simple-sidebars' ) ); + wp_die( esc_html__( 'Nice try, partner. But that sidebar doesn\'t exist. Click back and try again.', 'genesis-simple-sidebars' ) ); } +// phpcs:enable ?> -

+

-
+ - + +

- + + + + +

- +
-

- - -

-

+

diff --git a/includes/views/admin-main.php b/includes/views/admin-main.php index 2542455..7c5b9a2 100644 --- a/includes/views/admin-main.php +++ b/includes/views/admin-main.php @@ -1,25 +1,34 @@ -

+ + +

-

+

- - - + + + - - - + + + @@ -38,29 +47,29 @@
-

+

-
+
- + -

+

- + -

+

- +
-

+

diff --git a/includes/views/entry-metabox-content.php b/includes/views/entry-metabox-content.php index f728049..c7fcaf5 100644 --- a/includes/views/entry-metabox-content.php +++ b/includes/views/entry-metabox-content.php @@ -1,4 +1,10 @@ core->get_sidebars(); global $wp_registered_sidebars; wp_nonce_field( 'genesis-simple-sidebars-save-entry', 'genesis-simple-sidebars-save-entry-nonce' ); @@ -7,40 +13,45 @@ if ( is_registered_sidebar( 'header-right' ) ) : ?>

- +if ( is_registered_sidebar( 'sidebar' ) ) : + ?>

- +if ( is_registered_sidebar( 'sidebar-alt' ) ) : + ?>

-core->get_sidebars(); ?> + +$sidebars = Genesis_Simple_Sidebars()->core->get_sidebars(); +?> + +

- + - + - +
@@ -20,13 +28,13 @@
@@ -35,13 +43,13 @@ core->has_3_column_layout() ) : ?>
diff --git a/plugin.php b/plugin.php index a3c3cb8..3834039 100644 --- a/plugin.php +++ b/plugin.php @@ -1,20 +1,26 @@