├── .distignore ├── .editorconfig ├── .gitignore ├── .travis.yml ├── Gruntfile.js ├── LICENSE ├── bin └── install-wp-tests.sh ├── composer.json ├── package.json ├── phpcs.xml.dist ├── phpunit.xml.dist ├── readme.md ├── src ├── Admin.php ├── CLI.php ├── Dictate.php └── Utils.php ├── tests ├── bootstrap.php └── test-sample.php ├── vendor ├── autoload.php └── composer │ ├── ClassLoader.php │ ├── LICENSE │ ├── autoload_classmap.php │ ├── autoload_namespaces.php │ ├── autoload_psr4.php │ ├── autoload_real.php │ └── autoload_static.php └── wp-plugin-dictator.php /.distignore: -------------------------------------------------------------------------------- 1 | # A set of files you probably don't want in your WordPress.org distribution 2 | .distignore 3 | .editorconfig 4 | .git 5 | .gitignore 6 | .gitlab-ci.yml 7 | .travis.yml 8 | .DS_Store 9 | Thumbs.db 10 | behat.yml 11 | bin 12 | circle.yml 13 | composer.json 14 | composer.lock 15 | Gruntfile.js 16 | package.json 17 | phpunit.xml 18 | phpunit.xml.dist 19 | multisite.xml 20 | multisite.xml.dist 21 | phpcs.xml 22 | phpcs.xml.dist 23 | README.md 24 | wp-cli.local.yml 25 | tests 26 | vendor 27 | node_modules 28 | *.sql 29 | *.tar.gz 30 | *.zip 31 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs 2 | # editorconfig.org 3 | 4 | # WordPress Coding Standards 5 | # https://make.wordpress.org/core/handbook/coding-standards/ 6 | 7 | root = true 8 | 9 | [*] 10 | charset = utf-8 11 | end_of_line = lf 12 | insert_final_newline = true 13 | trim_trailing_whitespace = true 14 | indent_style = tab 15 | indent_size = 4 16 | 17 | [{.jshintrc,*.json,*.yml}] 18 | indent_style = space 19 | indent_size = 2 20 | 21 | [{*.txt,wp-config-sample.php}] 22 | end_of_line = crlf 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Thumbs.db 3 | wp-cli.local.yml 4 | node_modules/ 5 | *.sql 6 | *.tar.gz 7 | *.zip 8 | .idea 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: php 4 | 5 | notifications: 6 | email: 7 | on_success: never 8 | on_failure: change 9 | 10 | branches: 11 | only: 12 | - master 13 | 14 | cache: 15 | directories: 16 | - vendor 17 | - $HOME/.composer/cache 18 | 19 | matrix: 20 | include: 21 | - php: 7.1 22 | env: WP_VERSION=latest 23 | - php: 7.0 24 | env: WP_VERSION=latest 25 | - php: 5.6 26 | env: WP_VERSION=4.4 27 | - php: 5.6 28 | env: WP_VERSION=latest 29 | - php: 5.6 30 | env: WP_VERSION=trunk 31 | - php: 5.6 32 | env: WP_TRAVISCI=phpcs 33 | - php: 5.3 34 | env: WP_VERSION=latest 35 | 36 | before_script: 37 | - export PATH="$HOME/.composer/vendor/bin:$PATH" 38 | - | 39 | if [[ ! -z "$WP_VERSION" ]] ; then 40 | bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION 41 | if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." ]]; then 42 | composer global require "phpunit/phpunit=4.8.*" 43 | else 44 | composer global require "phpunit/phpunit=5.7.*" 45 | fi 46 | fi 47 | - | 48 | if [[ "$WP_TRAVISCI" == "phpcs" ]] ; then 49 | composer global require wp-coding-standards/wpcs 50 | phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs 51 | fi 52 | 53 | script: 54 | - | 55 | if [[ ! -z "$WP_VERSION" ]] ; then 56 | phpunit 57 | WP_MULTISITE=1 phpunit 58 | fi 59 | - | 60 | if [[ "$WP_TRAVISCI" == "phpcs" ]] ; then 61 | phpcs 62 | fi 63 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function( grunt ) { 2 | 3 | 'use strict'; 4 | var banner = '/**\n * <%= pkg.homepage %>\n * Copyright (c) <%= grunt.template.today("yyyy") %>\n * This file is generated automatically. Do not edit.\n */\n'; 5 | // Project configuration 6 | grunt.initConfig( { 7 | 8 | pkg: grunt.file.readJSON( 'package.json' ), 9 | 10 | addtextdomain: { 11 | options: { 12 | textdomain: 'wp-plugin-dictator', 13 | }, 14 | update_all_domains: { 15 | options: { 16 | updateDomains: true 17 | }, 18 | src: [ '*.php', '**/*.php', '!node_modules/**', '!php-tests/**', '!bin/**' ] 19 | } 20 | }, 21 | 22 | wp_readme_to_markdown: { 23 | your_target: { 24 | files: { 25 | 'README.md': 'readme.txt' 26 | } 27 | }, 28 | }, 29 | 30 | makepot: { 31 | target: { 32 | options: { 33 | domainPath: '/languages', 34 | mainFile: 'wp-plugin-dictator.php', 35 | potFilename: 'wp-plugin-dictator.pot', 36 | potHeaders: { 37 | poedit: true, 38 | 'x-poedit-keywordslist': true 39 | }, 40 | type: 'wp-plugin', 41 | updateTimestamp: true 42 | } 43 | } 44 | }, 45 | } ); 46 | 47 | grunt.loadNpmTasks( 'grunt-wp-i18n' ); 48 | grunt.loadNpmTasks( 'grunt-wp-readme-to-markdown' ); 49 | grunt.registerTask( 'i18n', ['addtextdomain', 'makepot'] ); 50 | grunt.registerTask( 'readme', ['wp_readme_to_markdown'] ); 51 | 52 | grunt.util.linefeed = '\n'; 53 | 54 | }; 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /bin/install-wp-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ $# -lt 3 ]; then 4 | echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" 5 | exit 1 6 | fi 7 | 8 | DB_NAME=$1 9 | DB_USER=$2 10 | DB_PASS=$3 11 | DB_HOST=${4-localhost} 12 | WP_VERSION=${5-latest} 13 | SKIP_DB_CREATE=${6-false} 14 | 15 | WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib} 16 | WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/} 17 | 18 | download() { 19 | if [ `which curl` ]; then 20 | curl -s "$1" > "$2"; 21 | elif [ `which wget` ]; then 22 | wget -nv -O "$2" "$1" 23 | fi 24 | } 25 | 26 | if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then 27 | WP_TESTS_TAG="tags/$WP_VERSION" 28 | elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then 29 | WP_TESTS_TAG="trunk" 30 | else 31 | # http serves a single offer, whereas https serves multiple. we only want one 32 | download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json 33 | grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json 34 | LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') 35 | if [[ -z "$LATEST_VERSION" ]]; then 36 | echo "Latest WordPress version could not be found" 37 | exit 1 38 | fi 39 | WP_TESTS_TAG="tags/$LATEST_VERSION" 40 | fi 41 | 42 | set -ex 43 | 44 | install_wp() { 45 | 46 | if [ -d $WP_CORE_DIR ]; then 47 | return; 48 | fi 49 | 50 | mkdir -p $WP_CORE_DIR 51 | 52 | if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then 53 | mkdir -p /tmp/wordpress-nightly 54 | download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip 55 | unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/ 56 | mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR 57 | else 58 | if [ $WP_VERSION == 'latest' ]; then 59 | local ARCHIVE_NAME='latest' 60 | else 61 | local ARCHIVE_NAME="wordpress-$WP_VERSION" 62 | fi 63 | download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz 64 | tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR 65 | fi 66 | 67 | download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php 68 | } 69 | 70 | install_test_suite() { 71 | # portable in-place argument for both GNU sed and Mac OSX sed 72 | if [[ $(uname -s) == 'Darwin' ]]; then 73 | local ioption='-i .bak' 74 | else 75 | local ioption='-i' 76 | fi 77 | 78 | # set up testing suite if it doesn't yet exist 79 | if [ ! -d $WP_TESTS_DIR ]; then 80 | # set up testing suite 81 | mkdir -p $WP_TESTS_DIR 82 | svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes 83 | svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data 84 | fi 85 | 86 | if [ ! -f wp-tests-config.php ]; then 87 | download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php 88 | # remove all forward slashes in the end 89 | WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") 90 | sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php 91 | sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php 92 | sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php 93 | sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php 94 | sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php 95 | fi 96 | 97 | } 98 | 99 | install_db() { 100 | 101 | if [ ${SKIP_DB_CREATE} = "true" ]; then 102 | return 0 103 | fi 104 | 105 | # parse DB_HOST for port or socket references 106 | local PARTS=(${DB_HOST//\:/ }) 107 | local DB_HOSTNAME=${PARTS[0]}; 108 | local DB_SOCK_OR_PORT=${PARTS[1]}; 109 | local EXTRA="" 110 | 111 | if ! [ -z $DB_HOSTNAME ] ; then 112 | if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then 113 | EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" 114 | elif ! [ -z $DB_SOCK_OR_PORT ] ; then 115 | EXTRA=" --socket=$DB_SOCK_OR_PORT" 116 | elif ! [ -z $DB_HOSTNAME ] ; then 117 | EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" 118 | fi 119 | fi 120 | 121 | # create database 122 | mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA 123 | } 124 | 125 | install_wp 126 | install_test_suite 127 | install_db 128 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wp-plugin-dictator/wp-plugin-dictator", 3 | "description": "Dictate which plugins should be active/inactive in a given environment", 4 | "type": "wordpress-plugin", 5 | "version": "1.0.0", 6 | "authors": [ 7 | { 8 | "name": "Ryan Kanner" 9 | } 10 | ], 11 | "config": { 12 | "optimize-autoloader": true 13 | }, 14 | "autoload": { 15 | "psr-4": { 16 | "WPPluginDictator\\": "src/" 17 | }, 18 | "classmap": [ 19 | "src/" 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "name": "wp-plugin-dictator", 4 | "version": "1.0.1", 5 | "main": "Gruntfile.js", 6 | "author": "Ryan Kanner", 7 | "devDependencies": { 8 | "grunt": "~0.4.5", 9 | "grunt-wp-i18n": "~0.5.0", 10 | "grunt-wp-readme-to-markdown": "~1.0.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /phpcs.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | Generally-applicable sniffs for WordPress plugins 4 | 5 | 6 | 7 | 8 | 9 | 10 | . 11 | 12 | 13 | 14 | 15 | */node_modules/* 16 | */vendor/* 17 | 18 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | ./tests/ 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## WP Plugin Dictator 2 | This WordPress plugin can be used to dictate which plugins should, and should not be active in a given environment. This is particularly useful for when you are using version control for your WordPress site, and have plugins that need to be active for things to function properly. 3 | 4 | ### Installation 5 | To use this plugin simply copy all of the code from this repository into your `mu-plugins` directory **IMPORTANT** - This plugin MUST be used as an mu-plugin to function properly. 6 | 7 | ### plugins.json 8 | The main feature of this plugin is consuming json configuration files, and using that data to determine which plugins should be active for the environment. 9 | 10 | By default, the plugin looks for config files at the following paths: 11 | - `/wp-content` 12 | - `/wp-content/mu-plugins` 13 | - `/wp-content/plugins` 14 | - `/wp-content/themes/{active_parent_theme}` 15 | - `/wp-content/themes/{active_child_theme}` 16 | 17 | You can also add additional paths with the `wp_plugin_dictator_config_paths` filter. 18 | 19 | Once the plugin has consumed all of these config files, it will also search for any config files within the plugins defined in these main configs, and merge them together. This allows individual plugins to define their own dependencies. 20 | 21 | #### Basic Usage 22 | Below is a basic example of what one of the plugins.json config files. You can use the `activate` array to note which plugins should be recommended to be active for the site, and the `deactivate` array to note which plugins should not be recommended for the environment. Any plugin in the deactivate array will override a plugin in the activate array, so if a plugin is in a deactivate array in any config file on your site, it will not be recommended for the site, even if it's in an activate array in another config file. 23 | ```json 24 | { 25 | "activate" : { 26 | "wordpress-seo/wp-seo.php" : {} 27 | }, 28 | "deactivate" : { 29 | "debug-bar/debug-bar.php" : {} 30 | } 31 | } 32 | ``` 33 | #### Force activation/deactivation 34 | Going beyond the basic example above, you can also force a plugin to be activated or deactivated for a site. This will remove any ability to turn the plugin on or off from the admin, or through any other means (CLI or REST). 35 | ```json 36 | { 37 | "activate" : { 38 | "jetpack/jetpack.php" : {}, 39 | "wordpress-seo/wp-seo.php" : { 40 | "force" : true 41 | } 42 | }, 43 | "deactivate" : { 44 | "debug-bar/debug-bar.php" : { 45 | "force" : true 46 | } 47 | } 48 | } 49 | ``` 50 | 51 | #### Custom path plugins 52 | In addition to dictating the status of plugins within the plugin directory, you can also include plugins from a custom path. You can use the `path` key to set the parent directory of where the plugin is located. Then you can use the `priority` key for when the plugin should be loaded. `0` = mu_plugins_loaded, `1` = plugins_loaded, `2` = after_setup_theme 53 | ```json 54 | { 55 | "activate" : { 56 | "wordpress-seo/wp-seo.php" : { 57 | "path" : "wp-content/custom-plugins", 58 | "priority" : 1 59 | } 60 | } 61 | } 62 | ``` 63 | 64 | #### Dynamic plugin dictating 65 | In addition to the config files you can also dictate plugins dynamically through code for when you need to activate/deactivate a plugin based on certain conditions. 66 | **NOTE** - These hooks and filters fire very early, so this needs to be done in a mu-plugin before the plugin dictator loads 67 | ```php 68 | add_action( 'wp_plugin_dictator_after_default_configs_built', 'wppd_require_plugin_dynamically' ); 69 | function wppd_require_plugin_dynamically() { 70 | 71 | if ( ! defined( 'WPPD_ENVIRONMENT' ) ) { 72 | return; 73 | } 74 | 75 | $plugin_config = Dictate::get_configs(); 76 | 77 | if ( 'staging' === WPPD_ENVIRONMENT ) { 78 | $plugin_config['activate']['my-debugger-plugin/my-debugger-plugin.php'] = [ 79 | 'path' => 'wp-content/custom-plugins', 80 | 'priority' => 1, 81 | ]; 82 | } else { 83 | $plugin_config['deactivate']['my-debugger-plugin/my-debugger-plugin.php'] = [ 84 | 'path' => 'wp-content/custom-plugins', 85 | 'force' => true, 86 | ]; 87 | } 88 | 89 | Dictate::set_configs( $plugin_config ); 90 | 91 | } 92 | ``` 93 | 94 | You can also load an entire config file dynamically if you have more than a handful of plugins that follow the same conditional. 95 | ```php 96 | function wppd_include_environment_config( $configs ) { 97 | 98 | if ( ! defined( 'WPPD_ENVIRONMENT' ) { 99 | return $configs; 100 | } 101 | 102 | $environment = WPPD_ENVIRONMENT; 103 | $configs[ $environment ] = 'wp-content/configs/' . $environment . '.json'; 104 | return $configs; 105 | 106 | } 107 | ``` 108 | ### WP-CLI Support 109 | In order to enforce the dictated plugins list from the configs, you can run `wp plugin dictate reset`. Which should give you the following output: 110 | ```shell 111 | Starting plugin reset... 112 | Success: Plugins reset 113 | ``` 114 | You can also get the list of dictated plugins with `wp plugin dictate list`, which should give you an output that looks like: 115 | ```shell 116 | +---------------------------------------------+----------+------------+-------+----------------------------------------------+------------+ 117 | | slug | activate | deactivate | force | path | status | 118 | +---------------------------------------------+----------+------------+-------+----------------------------------------------+------------+ 119 | | ad-layers/ad-layers.php | yes | | no | | active | 120 | | ai-logger/ai-logger.php | yes | | no | | not active | 121 | | amp-wp/amp.php | | yes | no | | not active | 122 | | Basic-Auth/basic-auth.php | yes | | yes | | active | 123 | | chartbeat/chartbeat.php | | yes | no | | not active | 124 | | co-authors-plus/co-authors-plus.php | yes | | no | wp-content/custom-plugins | active | 125 | +---------------------------------------------+----------+------------+-------+----------------------------------------------+------------+ 126 | ``` 127 | ### Attribution 128 | Props to the following projects and blog posts for giving me ideas / code. 129 | 130 | - https://deliciousbrains.com/dependency-management-wordpress-proposal/ 131 | - https://journal.rmccue.io/322/plugin-dependencies/ 132 | - http://ottopress.com/2012/themeplugin-dependencies/ 133 | - http://tgmpluginactivation.com/ 134 | - https://gist.github.com/felixarntz/daff4006112b60dfea677ca08fc0b31c 135 | -------------------------------------------------------------------------------- /src/Admin.php: -------------------------------------------------------------------------------- 1 | actions_to_remove = apply_filters( 'wp_plugin_dictator_actions_to_remove', [ 'delete', 'deactivate', 'activate' ] ); 33 | add_filter( 'plugin_action_links', [ $this, 'modify_plugin_links' ], 10, 2 ); 34 | add_filter( 'map_meta_cap', [ $this, 'filter_plugin_meta_caps' ], 0, 4 ); 35 | add_action( 'admin_notices', [ $this, 'plugin_mismatch_notice' ] ); 36 | add_action( 'load-plugins.php', [ $this, 'dictate_recommended_plugins' ] ); 37 | add_filter( 'views_plugins', [ $this, 'add_custom_path_tab' ] ); 38 | add_filter( 'all_plugins', [ $this, 'filter_plugin_list' ] ); 39 | 40 | } 41 | 42 | /** 43 | * Modify's the action links for registered plugins 44 | * 45 | * @param array $actions The array of action links for the plugin 46 | * @param string $plugin_basename The slug of the plugin 47 | * 48 | * @return array 49 | * @access public 50 | */ 51 | public function modify_plugin_links( $actions, $plugin_basename ) { 52 | 53 | /** 54 | * Remove actions for required plugins, and add a message about the plugin being enabled by code 55 | */ 56 | if ( in_array( $plugin_basename, Dictate::get_required_plugins(), true ) ) { 57 | 58 | if ( ! empty( $this->actions_to_remove ) && is_array( $this->actions_to_remove ) ) { 59 | foreach ( $this->actions_to_remove as $action_name ) { 60 | unset( $actions[ $action_name ] ); 61 | } 62 | } 63 | 64 | $actions['required'] = '' . __( 'Enabled by code', 'wp-plugin-dictator' ) . ''; 65 | 66 | } elseif ( in_array( $plugin_basename, Dictate::get_recommended_plugins(), true ) ) { 67 | 68 | /** 69 | * Add text about being a recommended plugin 70 | */ 71 | $actions['recommended'] = __( 'Recommended Plugin', 'wp-plugin-dictator' ); 72 | 73 | } 74 | 75 | if ( in_array( $plugin_basename, Dictate::get_deactivated_plugins( 'required' ), true ) ) { 76 | 77 | /** 78 | * Don't allow plugins to be activated if they are force deactivated 79 | */ 80 | unset( $actions['activate'] ); 81 | unset( $actions['recommended'] ); 82 | unset( $actions['required'] ); 83 | $actions['deactivated'] = __( 'This plugin has been deactivated by code', 'wp-plugin-dictator' ); 84 | 85 | } 86 | 87 | if ( ! empty( $_GET['plugin_status'] ) && 'custom-path' === sanitize_text_field( $_GET['plugin_status'] ) ) { 88 | $actions = [ 'required' => '' . __( 'Enabled by code', 'wp-plugin-dictator' ) . '' ]; 89 | } 90 | 91 | return $actions; 92 | 93 | } 94 | 95 | /** 96 | * Filters the capabilities for activating and deactivating plugins. 97 | * 98 | * This method prevents access to those capabilities for plugins that are deemed required 99 | * 100 | * @param array $caps List of primitive capabilities resolved to in `map_meta_cap()`. 101 | * @param string $cap Meta capability actually being checked. 102 | * @param int $user_id User ID for which the capability is being checked. 103 | * @param array $args Additional arguments passed to the capability check. 104 | * 105 | * @return array Filtered value of $caps. 106 | * @access public 107 | */ 108 | public function filter_plugin_meta_caps( array $caps, $cap, $user_id, array $args ) { 109 | switch ( $cap ) { 110 | case 'activate_plugin': 111 | if ( in_array( $args[0], Dictate::get_deactivated_plugins( 'required' ), true ) ) { 112 | $caps[] = 'do_not_allow'; 113 | } 114 | case 'deactivate_plugin': 115 | case 'delete_plugin': 116 | if ( in_array( $args[0], Dictate::get_required_plugins(), true ) ) { 117 | $caps[] = 'do_not_allow'; 118 | } 119 | break; 120 | /* 121 | * Core does not actually have 'delete_plugin' yet, so this is a bad but 122 | * necessary hack to prevent deleting one of these plugins loaded as MU. 123 | */ 124 | case 'delete_plugins': 125 | if ( isset( $_REQUEST['checked'] ) ) { 126 | $plugins = wp_unslash( $_REQUEST['checked'] ); 127 | if ( array_intersect( $plugins, Dictate::get_required_plugins() ) ) { 128 | $caps[] = 'do_not_allow'; 129 | } 130 | } 131 | break; 132 | } 133 | return $caps; 134 | 135 | } 136 | 137 | /** 138 | * Displays a notice about plugins that don't match up with the current environment configuration 139 | * 140 | * @return void 141 | * @access public 142 | */ 143 | public function plugin_mismatch_notice() { 144 | 145 | $screen = get_current_screen(); 146 | 147 | if ( 'plugins' === $screen->id ) { 148 | 149 | $plugins_active = ( ! empty( Dictate::get_dictated_plugins() ) ) ? Dictate::get_dictated_plugins() : []; 150 | $plugins_recommended = ( ! empty( Dictate::get_recommended_plugins() ) ) ? Dictate::get_recommended_plugins() : []; 151 | $plugins_required = ( ! empty( Dictate::get_required_plugins() ) ) ? Dictate::get_required_plugins() : []; 152 | 153 | $should_be_active = array_diff( $plugins_recommended, $plugins_active ); 154 | $should_not_be_active = array_diff( $plugins_active, array_merge( $plugins_recommended, $plugins_required ) ); 155 | 156 | $message = ''; 157 | 158 | if ( ! empty( $should_be_active ) ) { 159 | $message .= '

' . __( 'The following plugins are not active, but are recommended', 'wp-plugin-dictator' ) . ': ' . implode( $should_be_active, ', ' ); 160 | } 161 | 162 | if ( ! empty( $should_not_be_active ) ) { 163 | $message .= '

' . __( 'The following plugins are active but they are not recommended', 'wp-plugin-dictator' ) . ':' . implode( $should_not_be_active, ', ' ); 164 | } 165 | 166 | if ( ! empty( $message ) ) { 167 | 168 | $url = add_query_arg( 169 | [ 170 | 'reset_plugins' => '', 171 | '_wpnonce' => wp_create_nonce( 'reset-plugins' ), 172 | ], 173 | admin_url( 'plugins.php' ) 174 | ); 175 | 176 | echo '

' . 177 | esc_html__( 'WARNING: The plugins active don\'t match what is recommended for this environment.', 'wp-plugin-dictator' ) . 178 | wp_kses_post( $message ) . 179 | '

' . esc_html__( 'Reset Plugins', 'wp-plugin-dictator' ) . '' . 180 | '

'; 181 | 182 | } 183 | } 184 | 185 | } 186 | 187 | /** 188 | * Reset the recommended plugins reset on page load 189 | * 190 | * @return void 191 | * @access public 192 | */ 193 | public function dictate_recommended_plugins() { 194 | 195 | $needs_update = ( isset( $_GET['reset_plugins'] ) ) ? true : false; 196 | $nonce = ( ! empty( $_GET['_wpnonce'] ) ) ? $_GET['_wpnonce'] : ''; 197 | 198 | if ( ! wp_verify_nonce( $nonce, 'reset-plugins' ) ) { 199 | return; 200 | } 201 | 202 | if ( true === $needs_update && current_user_can( 'activate_plugins' ) ) { 203 | 204 | Dictate::reset_plugins(); 205 | 206 | } 207 | 208 | header("Refresh:0; url=" . admin_url( 'plugins.php' ) ); 209 | 210 | } 211 | 212 | /** 213 | * Add a new tab for custom path plugins 214 | * 215 | * @param array $tabs The tabs for the page 216 | * 217 | * @return mixed 218 | * @access public 219 | */ 220 | public function add_custom_path_tab( $tabs ) { 221 | 222 | $custom_path_plugins = Dictate::get_custom_path_plugins( true ); 223 | 224 | if ( empty( $custom_path_plugins ) ) { 225 | return $tabs; 226 | } 227 | 228 | $custom_path_tab = sprintf( 229 | '%3$s(%4$d)', 230 | ( ! empty( $_GET['plugin_status'] ) && 'custom-path' === sanitize_text_field( $_GET['plugin_status'] ) ) ? 'current' : '', 231 | add_query_arg( 'plugin_status', 'custom-path', 'plugins.php' ), 232 | __( 'Custom Path', 'wp-plugin-dictator' ), 233 | count( $custom_path_plugins ) 234 | ); 235 | $tabs['custom-path'] = $custom_path_tab; 236 | return $tabs; 237 | 238 | } 239 | 240 | /** 241 | * Filter out regular plugins for the custom path plugin list 242 | * 243 | * @param array $plugins The array of plugins to be filtered 244 | * 245 | * @return array 246 | * @access public 247 | */ 248 | public function filter_plugin_list( $plugins ) { 249 | 250 | if ( empty( $_GET['plugin_status'] ) || 'custom-path' !== sanitize_text_field( $_GET['plugin_status'] ) ) { 251 | return $plugins; 252 | } 253 | 254 | $clean_plugins = []; 255 | $custom_path_plugins = Dictate::get_custom_path_plugins( true ); 256 | if ( ! empty( $custom_path_plugins ) && is_array( $custom_path_plugins ) ) { 257 | foreach ( $custom_path_plugins as $plugin_slug => $data ) { 258 | $plugin_data = get_plugin_data( $data['path'] ); 259 | if ( empty( $plugin_data['Name'] ) ) { 260 | $plugin_data['Name'] = $plugin_slug; 261 | } 262 | $clean_plugins[ $plugin_slug ] = $plugin_data; 263 | } 264 | } 265 | 266 | return $clean_plugins; 267 | 268 | } 269 | 270 | } 271 | -------------------------------------------------------------------------------- /src/CLI.php: -------------------------------------------------------------------------------- 1 | ...] 47 | * : Optionally pass the plugin slugs you want the info for 48 | * 49 | * [--fields] 50 | * : Fields to display data for 51 | * --- 52 | * default: all 53 | * options: 54 | * - slug 55 | * - activate 56 | * - deactivate 57 | * - force 58 | * - path 59 | * - status 60 | * --- 61 | * 62 | * [--format] 63 | * : Render the output in a particular format 64 | * --- 65 | * default: table 66 | * options: 67 | * - table 68 | * - csv 69 | * - ids 70 | * - json 71 | * - yaml 72 | * --- 73 | * 74 | * [--=] 75 | * : One or more fields to filter the list with 76 | * 77 | * ## EXAMPLES 78 | * 79 | * $ wp plugin dictate list 80 | * +-----------------------------------------------+----------+------------+-------+----------+------------+ 81 | * | slug | activate | deactivate | force | path | status | 82 | * +-----------------------------------------------+----------+------------+-------+----------+------------+ 83 | * | My-Plugin/my-plugin.php | yes | | yes | | active | 84 | * | co-authors-plus/co-authors-plus.php | yes | | yes | | active | 85 | * | OAuth1/oauth-server.php | yes | | no | | active | 86 | * | post-meta-inspector/post-meta-inspector.php | yes | | no | | active | 87 | * +-----------------------------------------------+----------+------------+-------+----------+------------+ 88 | * 89 | * $ wp plugin dictate list my-plugin/my-plugin.php 90 | * +-------------------------+----------+------------+-------+------+----------+ 91 | * | slug | activate | deactivate | force | path | status | 92 | * +-------------------------+----------+------------+-------+------+----------+ 93 | * | my-plugin/my-plugin.php | | yes | no | | active | 94 | * +-------------------------+----------+------------+-------+------+----------+ 95 | * 96 | * @param array $args 97 | * @param array $assoc_args 98 | */ 99 | public function list( $args, $assoc_args ) { 100 | 101 | $plugins = Dictate::get_configs(); 102 | $this->supported_props = [ 'slug', 'activate', 'deactivate', 'force', 'path', 'status' ]; 103 | if ( empty( $plugins ) || ! is_array( $plugins ) ) { 104 | WP_CLI::error( 'No plugins found to list' ); 105 | } 106 | 107 | $clean_plugins = []; 108 | if ( ! empty( $plugins['activate'] ) && is_array( $plugins['activate'] ) ) { 109 | foreach ( $plugins['activate'] as $plugin_slug => $settings ) { 110 | $clean_plugins[ $plugin_slug ] = $this->build_plugin_atts( $plugin_slug, $settings, 'yes', '' ); 111 | } 112 | } 113 | 114 | if ( ! empty( $plugins['deactivate'] && is_array( $plugins['deactivate'] ) ) ) { 115 | foreach ( $plugins['deactivate'] as $plugin_slug => $settings ) { 116 | $clean_plugins[ $plugin_slug ] = $this->build_plugin_atts( $plugin_slug, $settings, '', 'yes' ); 117 | } 118 | } 119 | 120 | if ( ! empty( $args ) && ! empty( $clean_plugins ) ) { 121 | $clean_plugins = array_intersect_key( $clean_plugins, array_flip( $args ) ); 122 | } 123 | 124 | if ( ! empty( $assoc_args ) ) { 125 | $filter_args = array_intersect_key( $assoc_args, array_flip( $this->supported_props ) ); 126 | $clean_plugins = wp_list_filter( $clean_plugins, $filter_args ); 127 | } 128 | 129 | $this->format_output( $clean_plugins, $assoc_args ); 130 | 131 | } 132 | 133 | /** 134 | * Handles the formatting of output 135 | * 136 | * @param array $plugins The data to display 137 | * @param array $assoc_args Args so we know how to display it 138 | * 139 | * @return void 140 | * @access private 141 | */ 142 | private function format_output( $plugins, $assoc_args ) { 143 | if ( ! empty( $assoc_args['fields'] ) ) { 144 | if ( is_string( $assoc_args['fields'] ) ) { 145 | $fields = explode( ',', $assoc_args['fields'] ); 146 | } else { 147 | $fields = $assoc_args['fields']; 148 | } 149 | $fields = array_intersect( $fields, $this->supported_props ); 150 | } else { 151 | $fields = $this->supported_props; 152 | } 153 | $formatter = new \WP_CLI\Formatter( $assoc_args, $fields ); 154 | $formatter->display_items( $plugins ); 155 | } 156 | 157 | /** 158 | * Builds the plugin attributes 159 | * 160 | * @param string $plugin_slug The name of the slug 161 | * @param array $settings Settings for the plugin 162 | * @param string $activate Value of the 'active' key in the array 163 | * @param string $deactivate Value of the 'deactive' key in the array 164 | * 165 | * @return array 166 | * @access private 167 | */ 168 | private function build_plugin_atts( $plugin_slug, $settings, $activate, $deactivate ) { 169 | return [ 170 | 'slug' => $plugin_slug, 171 | 'activate' => $activate, 172 | 'deactivate' => $deactivate, 173 | 'force' => ( isset( $settings['force'] ) ) ? 'yes' : 'no', 174 | 'path' => ( ! empty( $settings['path'] ) ) ? $settings['path'] : '', 175 | 'status' => $this->get_plugin_status( $plugin_slug, $settings ) 176 | ]; 177 | } 178 | 179 | /** 180 | * Get the status of the plugin, active vs not active 181 | * 182 | * @param string $plugin_slug The name of the plugin 183 | * @param array $settings Settings for the registered plugin 184 | * 185 | * @return string 186 | * @access private 187 | */ 188 | private function get_plugin_status( $plugin_slug, $settings ) { 189 | 190 | if ( ! empty( $settings['path'] ) ) { 191 | return 'active'; 192 | } 193 | 194 | if ( false !== array_search( $plugin_slug, $this->get_active_plugins(), true ) ) { 195 | return 'active'; 196 | } else { 197 | return 'not active'; 198 | } 199 | 200 | } 201 | 202 | /** 203 | * Retrieve the active plugins 204 | * 205 | * @return array 206 | * @access private 207 | */ 208 | private function get_active_plugins() { 209 | 210 | if ( empty( self::$active_plugins ) ) { 211 | self::$active_plugins = get_option( 'active_plugins' ); 212 | } 213 | 214 | return self::$active_plugins; 215 | 216 | } 217 | 218 | 219 | } 220 | -------------------------------------------------------------------------------- /src/Dictate.php: -------------------------------------------------------------------------------- 1 | default_priority = apply_filters( 'wp_plugin_dictator_default_custom_path_priority', 1 ); 90 | 91 | $this->get_general_configs(); 92 | 93 | /** 94 | * Fires after the initial plugin configs have been consumed and built. At this point you 95 | * can add your own plugins to require or recommend for the environment. 96 | */ 97 | do_action( 'wp_plugin_dictator_after_default_configs_built' ); 98 | 99 | $this->get_plugin_configs(); 100 | $this->dictate_plugin_loading(); 101 | 102 | /** 103 | * Where the magic happens 104 | */ 105 | add_filter( 'option_active_plugins', [ $this, 'dictate_required_plugins' ] ); 106 | 107 | /** 108 | * Hack for loading plugins early on WordPress VIP. 109 | */ 110 | if ( did_action( 'muplugins_loaded' ) && ! did_action( 'plugins_loaded' ) ) { 111 | $this->load_custom_path_plugins( true, 0 ); 112 | } 113 | 114 | add_action( 'muplugins_loaded', [ $this, 'load_custom_path_plugins' ] ); 115 | add_action( 'plugins_loaded', [ $this, 'load_custom_path_plugins' ] ); 116 | add_action( 'after_setup_theme', [ $this, 'load_custom_path_plugins' ] ); 117 | 118 | } 119 | 120 | /** 121 | * Returns the array of merged & built configs 122 | * 123 | * @return array 124 | * @access public 125 | */ 126 | public static function get_configs() { 127 | return self::$configs; 128 | } 129 | 130 | /** 131 | * Sets the config data to the static config variable 132 | * 133 | * @param array $data The data to set to the configs variable 134 | * @access public 135 | */ 136 | public static function set_configs( $data ) { 137 | self::$configs = $data; 138 | } 139 | 140 | /** 141 | * Retrieves any errors that happen when building configs / setting plugins for display 142 | * 143 | * @return array 144 | * @access public 145 | */ 146 | public static function get_all_errors() { 147 | return self::$errors; 148 | } 149 | 150 | /** 151 | * Gets the list of plugins that are recommended for the environment 152 | * 153 | * @return array 154 | * @access public 155 | */ 156 | public static function get_recommended_plugins() { 157 | return self::$recommended_plugins; 158 | } 159 | 160 | /** 161 | * Gets the list of plugins that are required for the environment 162 | * 163 | * @return array 164 | * @access public 165 | */ 166 | public static function get_required_plugins() { 167 | return self::$required_plugins; 168 | } 169 | 170 | /** 171 | * Gets the list of plugins that have been marked as "deactivate" for the environment 172 | * 173 | * @param bool|string $slice Which deactivated array you want to retrieve, recommended or required 174 | * 175 | * @return array 176 | * @access public 177 | */ 178 | public static function get_deactivated_plugins( $slice = false ) { 179 | if ( ! empty( $slice ) ) { 180 | return ( ! empty( self::$deactivated_plugins[ $slice ] ) ) ? self::$deactivated_plugins[ $slice ] : []; 181 | } else { 182 | return self::$deactivated_plugins; 183 | } 184 | } 185 | 186 | /** 187 | * Return the array of dictated plugins 188 | * 189 | * @return array 190 | * @access public 191 | */ 192 | public static function get_dictated_plugins() { 193 | return self::$dictated_plugins; 194 | } 195 | 196 | /** 197 | * Returns an array of the custom path plugins 198 | * 199 | * @param bool $flat Return as a single flat array or as a multidimensional array 200 | * @param int $priority The slice of the array to return by registered priority 201 | * 202 | * @return array|mixed 203 | */ 204 | public static function get_custom_path_plugins( $flat = false, $priority = 0 ) { 205 | 206 | if ( false === $flat ) { 207 | return ( ! empty( self::$custom_plugin_paths[ $priority ] ) ) ? self::$custom_plugin_paths[ $priority ] : []; 208 | } else { 209 | $clean_plugins = []; 210 | if ( ! empty( self::$custom_plugin_paths ) && is_array( self::$custom_plugin_paths ) ) { 211 | foreach ( self::$custom_plugin_paths as $priority => $plugins ) { 212 | if ( ! empty( $plugins ) && is_array( $plugins ) ) { 213 | foreach ( $plugins as $plugin_slug => $path ) { 214 | $clean_plugins[ $plugin_slug ] = [ 215 | 'priority' => $priority, 216 | 'path' => $path, 217 | ]; 218 | } 219 | } 220 | } 221 | } 222 | return $clean_plugins; 223 | } 224 | } 225 | 226 | /** 227 | * Build a config based off of the plugins.json files in general places like the wp-content folder 228 | * 229 | * @return void 230 | * @access private 231 | */ 232 | private function get_general_configs() { 233 | 234 | $config = []; 235 | $paths = Utils::get_config_paths(); 236 | 237 | if ( is_array( $paths ) && ! empty( $paths ) ) { 238 | foreach ( $paths as $path ) { 239 | if ( file_exists( $path ) && 0 === validate_file( $path ) ) { 240 | $data = file_get_contents( $path ); 241 | if ( ! empty( $data = json_decode( $data, true ) ) ) { 242 | $config = array_merge_recursive( $config, $data ); 243 | } 244 | } 245 | } 246 | } 247 | 248 | $config = apply_filters( 'wp_plugin_dictator_get_general_config', $config ); 249 | self::set_configs( $config ); 250 | 251 | } 252 | 253 | /** 254 | * Get configs from each of the individual plugins already registered from the general configs 255 | * 256 | * @return void 257 | * @access private 258 | */ 259 | private function get_plugin_configs() { 260 | 261 | $general_config = self::get_configs(); 262 | 263 | if ( ! empty( $general_config['activate'] ) && is_array( $general_config['activate'] ) ) { 264 | foreach ( $general_config['activate'] as $plugin_slug => $settings ) { 265 | $path = ( ! empty( $settings['path'] ) ) ? $settings['path'] : ''; 266 | $config_path = apply_filters( 'wp_plugin_dictator_plugin_config_file_path', Utils::get_config_for_plugin( $plugin_slug, $path ) ); 267 | if ( file_exists( $config_path ) && 0 === validate_file( $config_path ) ) { 268 | $data = file_get_contents( $config_path ); 269 | if ( ! empty( $data = json_decode( $data, true ) ) ) { 270 | $general_config = array_merge_recursive( $general_config, $data ); 271 | } 272 | } 273 | } 274 | 275 | self::set_configs( $general_config ); 276 | 277 | } 278 | 279 | } 280 | 281 | /** 282 | * Defines which plugins should/shouldn't be active for the environment 283 | * 284 | * @access private 285 | * @return void 286 | */ 287 | private function dictate_plugin_loading() { 288 | 289 | $plugins = self::get_configs(); 290 | 291 | /** 292 | * Loop through the plugins in the activate array to figure out which ones should be force activated 293 | */ 294 | if ( ! empty( $plugins['activate'] ) && is_array( $plugins['activate'] ) ) { 295 | foreach ( $plugins['activate'] as $plugin_slug => $settings ) { 296 | 297 | if ( ! empty( $settings['path'] ) ) { 298 | $priority = ( ! empty( $settings['priority'] ) ) ? absint( $settings['priority'] ) : $this->default_priority; 299 | self::add_custom_path_plugin( $plugin_slug, $settings['path'], $priority ); 300 | } else { 301 | self::register_plugin( $plugin_slug, $settings ); 302 | } 303 | 304 | } 305 | 306 | } 307 | 308 | /** 309 | * Loop through plugins in the deactivate array and remove any of the plugins that may be 310 | * registered as active already. Also force deactivate them so they can't be activated 311 | * through the admin or anything. 312 | */ 313 | if ( ! empty( $plugins['deactivate'] ) && is_array( $plugins['deactivate'] ) ) { 314 | foreach ( $plugins['deactivate'] as $plugin_slug => $settings ) { 315 | 316 | if ( ! empty( $settings['path'] ) ) { 317 | $priority = ( ! empty( $settings['priority'] ) ) ? absint( $settings['priority'] ) : $this->default_priority; 318 | self::remove_custom_path_plugin( $plugin_slug, $priority ); 319 | } else { 320 | $force = ( isset( $settings['force'] ) ) ? (bool) $settings['force'] : false; 321 | self::deactivate_plugin( $plugin_slug, $force ); 322 | } 323 | } 324 | } 325 | 326 | } 327 | 328 | /** 329 | * Dictates which plugins should be force activated/deactivated 330 | * 331 | * @param array $plugins The plugins that are active in the database 332 | * 333 | * @return array 334 | * @access public 335 | */ 336 | public function dictate_required_plugins( $plugins ) { 337 | 338 | if ( empty( self::$dictated_plugins ) ) { 339 | 340 | $dictated_plugins = array_unique( array_merge( $plugins, self::$required_plugins ) ); 341 | $deactivated_plugins = ( ! empty( self::$deactivated_plugins['required'] ) ) ? self::$deactivated_plugins['required'] : []; 342 | 343 | if ( ! empty( $dictated_plugins ) ) { 344 | $dictated_plugins = array_diff( $dictated_plugins, $deactivated_plugins ); 345 | } else { 346 | $dictated_plugins = $plugins; 347 | } 348 | 349 | self::$dictated_plugins = $dictated_plugins; 350 | 351 | } 352 | 353 | return self::$dictated_plugins; 354 | 355 | } 356 | 357 | /** 358 | * Registers a plugin to be activated when we go to load plugins 359 | * 360 | * @param string $plugin_slug Slug of the plugin to register 361 | * @param array $settings Plugin settings 362 | * 363 | * @access public 364 | * @return void 365 | */ 366 | public static function register_plugin( $plugin_slug, $settings ) { 367 | 368 | if ( ! empty( $settings['force'] ) && true === $settings['force'] ) { 369 | if ( false === array_search( $plugin_slug, self::$required_plugins, true ) ) { 370 | self::$required_plugins[] = $plugin_slug; 371 | } 372 | } else { 373 | if ( false === array_search( $plugin_slug, self::$recommended_plugins, true ) ) { 374 | self::$recommended_plugins[] = $plugin_slug; 375 | } 376 | } 377 | } 378 | 379 | /** 380 | * Dictate which plugins should be force deactivated 381 | * 382 | * @param string $plugin_slug Slug for the plugin to deactivate 383 | * @param bool $force Whether or not the plugin should be force deactivated or not 384 | * 385 | * @return void 386 | * @access public 387 | */ 388 | public static function deactivate_plugin( $plugin_slug, $force = false ) { 389 | 390 | if ( true === $force ) { 391 | if ( empty( self::$deactivated_plugins['required'] ) || false === array_search( $plugin_slug, self::$deactivated_plugins['required'], true ) ) { 392 | self::$deactivated_plugins['required'][] = $plugin_slug; 393 | } 394 | } else { 395 | if ( empty( self::$deactivated_plugins['recommended'] ) || false === array_search( $plugin_slug, self::$deactivated_plugins['recommended'], true ) ) { 396 | self::$deactivated_plugins['recommended'][] = $plugin_slug; 397 | } 398 | } 399 | 400 | if ( false !== ( $key = array_search( $plugin_slug, self::$required_plugins, true ) ) ) { 401 | unset( self::$required_plugins[ $key ] ); 402 | } else if ( false !== ( $key = array_search( $plugin_slug, self::$recommended_plugins, true ) ) ) { 403 | unset( self::$recommended_plugins[ $key ] ); 404 | } 405 | 406 | } 407 | 408 | /** 409 | * Handles registering plugins that have a custom path 410 | * 411 | * @param string $plugin_slug Slug of the plugin to register 412 | * @param string $path Path of the parent directory (excluding plugin slug) where the 413 | * plugin is located 414 | * @param int $priority Priority number of when the plugin should be loaded. 1, 2, or 3. 415 | * 416 | * @return void 417 | * @access public 418 | */ 419 | public static function add_custom_path_plugin( $plugin_slug, $path, $priority ) { 420 | 421 | $folder_path = Utils::build_custom_plugin_base_path( $path ); 422 | self::$custom_plugin_paths[ $priority ][ $plugin_slug ] = trailingslashit( $folder_path ) . $plugin_slug; 423 | 424 | } 425 | 426 | /** 427 | * Remove a custom path plugin from being loaded 428 | * 429 | * @param string $plugin_slug Slug of the plugin to remove 430 | * @param int $priority Priority number of when the plugin should be loaded. 1, 2, or 3. 431 | * 432 | * @access public 433 | * @return void 434 | */ 435 | public static function remove_custom_path_plugin( $plugin_slug, $priority ) { 436 | if ( array_key_exists( $plugin_slug, self::$custom_plugin_paths[ $priority ] ) ) { 437 | unset( self::$custom_plugin_paths[ $priority ][ $plugin_slug ] ); 438 | } 439 | } 440 | 441 | /** 442 | * @TODO: Sort out what to do with this... 443 | * 444 | * @param string $plugin_slug The slug of the plugin that had an issue 445 | * @param string $message The error message 446 | */ 447 | public function add_error( $plugin_slug, $message ) { 448 | self::$errors[ $plugin_slug ] = $message; 449 | } 450 | 451 | /** 452 | * Handles the loading of the custom path plugins. 453 | * 454 | * @param bool $now Whether or not to run the loading right now 455 | * @param int $slice The priority of the plugins to load 456 | * 457 | * @return void 458 | * @access public 459 | */ 460 | public function load_custom_path_plugins( $now = false, $slice = 0 ) { 461 | 462 | if ( true !== $now ) { 463 | switch ( current_action() ) { 464 | case 'muplugins_loaded': 465 | $slice = 0; 466 | break; 467 | case 'plugins_loaded': 468 | $slice = 1; 469 | break; 470 | case 'after_setup_theme': 471 | $slice = 2; 472 | break; 473 | default: 474 | $slice = false; 475 | break; 476 | } 477 | } 478 | 479 | if ( false === $slice ) { 480 | return; 481 | } 482 | 483 | $plugins_to_load = ( ! empty( self::$custom_plugin_paths[ $slice ] ) ) ? self::$custom_plugin_paths[ $slice ] : []; 484 | 485 | if ( ! empty( $plugins_to_load ) && is_array( $plugins_to_load ) ) { 486 | foreach ( $plugins_to_load as $plugin_to_load ) { 487 | if ( file_exists( $plugin_to_load ) && 0 === validate_file( $plugin_to_load ) ) { 488 | require_once( $plugin_to_load ); 489 | } 490 | } 491 | } 492 | 493 | } 494 | 495 | /** 496 | * Method to reset the plugins to what is recommended for the environment 497 | * 498 | * @return void 499 | * @access public 500 | */ 501 | public static function reset_plugins() { 502 | 503 | $recommended_plugins = ( ! empty( self::get_recommended_plugins() ) ) ? self::get_recommended_plugins() : []; 504 | $required_plugins = ( ! empty( self::get_required_plugins() ) ) ? self::get_required_plugins() : []; 505 | $active_plugins = get_option( 'active_plugins' ); 506 | 507 | $missing_plugins = array_diff( $recommended_plugins, $active_plugins ); 508 | $extra_plugins = array_diff( $active_plugins, array_merge( $recommended_plugins, $required_plugins ) ); 509 | 510 | if ( ! empty( $missing_plugins ) ) { 511 | $active_plugins = array_merge( $active_plugins, $missing_plugins ); 512 | foreach ( $missing_plugins as $missing_plugin ) { 513 | do_action( 'activate_' . $missing_plugin ); 514 | } 515 | } 516 | 517 | if ( ! empty( $extra_plugins ) ) { 518 | $active_plugins = array_diff( $active_plugins, $extra_plugins ); 519 | foreach ( $extra_plugins as $extra_plugin ) { 520 | do_action( 'deactivate_' . $extra_plugin ); 521 | } 522 | } 523 | 524 | update_option( 'active_plugins', $active_plugins ); 525 | 526 | } 527 | 528 | } 529 | -------------------------------------------------------------------------------- /src/Utils.php: -------------------------------------------------------------------------------- 1 | self::build_filepath( WP_CONTENT_DIR ), 29 | 'mu_plugins' => self::build_filepath( WPMU_PLUGIN_DIR ), 30 | 'plugins' => self::build_filepath( WP_PLUGIN_DIR ), 31 | 'parent_theme' => self::build_filepath( get_template_directory() ), 32 | 'child_theme' => self::build_filepath( get_stylesheet_directory() ), 33 | ]; 34 | } 35 | 36 | /** 37 | * Filters the list of file paths to plugins.json files that should be checked to build the initial configuration for the project 38 | * 39 | * @param array $paths The paths that are checked by default 40 | * @return array 41 | */ 42 | return apply_filters( 'wp_plugin_dictator_config_paths', self::$paths ); 43 | 44 | } 45 | 46 | /** 47 | * Gets the filename of the config pile given a path 48 | * 49 | * @param string $path path to the parent dir containing the config file 50 | * 51 | * @return string 52 | * @access public 53 | */ 54 | public static function get_config_file_name( $path ) { 55 | 56 | /** 57 | * Returns the name of the json file to consume 58 | * 59 | * @param string $path Filepath to the parent directory containing the config file 60 | * 61 | * @return string 62 | */ 63 | return apply_filters( 'wp_plugin_dictator_config_file_name', 'plugins', $path ); 64 | 65 | } 66 | 67 | /** 68 | * Retrieve the full filepath to a plugin's config file 69 | * 70 | * @param string $plugin_slug The slug of the plugin to get a config for 71 | * @param string $path Parent directory of the plugin 72 | * 73 | * @return string 74 | * @access public 75 | */ 76 | public static function get_config_for_plugin( $plugin_slug, $path = '' ) { 77 | 78 | $plugin_slug_parts = explode( '/', $plugin_slug ); 79 | 80 | if ( empty( $plugin_slug_parts[0] ) ) { 81 | return ''; 82 | } 83 | 84 | if ( ! empty( $path ) ) { 85 | $plugin_path = trailingslashit( self::build_custom_plugin_base_path( $path ) ) . $plugin_slug_parts[0]; 86 | } else { 87 | $plugin_path = trailingslashit( WP_PLUGIN_DIR ) . $plugin_slug_parts[0]; 88 | } 89 | 90 | return apply_filters( 'wp_plugin_dictator_plugin_config', self::build_filepath( $plugin_path ), $plugin_slug ); 91 | 92 | } 93 | 94 | /** 95 | * Builds the full filepath to the json config file 96 | * 97 | * @param string $path Full path to the plugin 98 | * 99 | * @return string 100 | * @access private 101 | */ 102 | private static function build_filepath( $path ) { 103 | return trailingslashit( $path ) . self::get_config_file_name( $path ) . '.json'; 104 | } 105 | 106 | /** 107 | * Builds the plugin base path for a custom path plugin 108 | * 109 | * @param string $path Parent directory of the custom path plugin 110 | * 111 | * @return string 112 | */ 113 | public static function build_custom_plugin_base_path( $path ) { 114 | 115 | $root = ''; 116 | 117 | if ( false === strpos( $path, ABSPATH ) ) { 118 | if ( '/' === substr( $path, 0, 1 ) ) { 119 | $root = untrailingslashit( ABSPATH ); 120 | } else { 121 | $root = ABSPATH; 122 | } 123 | } 124 | 125 | return $root . $path; 126 | 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | assertTrue( true ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /vendor/autoload.php: -------------------------------------------------------------------------------- 1 | 7 | * Jordi Boggiano 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Composer\Autoload; 14 | 15 | /** 16 | * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. 17 | * 18 | * $loader = new \Composer\Autoload\ClassLoader(); 19 | * 20 | * // register classes with namespaces 21 | * $loader->add('Symfony\Component', __DIR__.'/component'); 22 | * $loader->add('Symfony', __DIR__.'/framework'); 23 | * 24 | * // activate the autoloader 25 | * $loader->register(); 26 | * 27 | * // to enable searching the include path (eg. for PEAR packages) 28 | * $loader->setUseIncludePath(true); 29 | * 30 | * In this example, if you try to use a class in the Symfony\Component 31 | * namespace or one of its children (Symfony\Component\Console for instance), 32 | * the autoloader will first look for the class under the component/ 33 | * directory, and it will then fallback to the framework/ directory if not 34 | * found before giving up. 35 | * 36 | * This class is loosely based on the Symfony UniversalClassLoader. 37 | * 38 | * @author Fabien Potencier 39 | * @author Jordi Boggiano 40 | * @see http://www.php-fig.org/psr/psr-0/ 41 | * @see http://www.php-fig.org/psr/psr-4/ 42 | */ 43 | class ClassLoader 44 | { 45 | // PSR-4 46 | private $prefixLengthsPsr4 = array(); 47 | private $prefixDirsPsr4 = array(); 48 | private $fallbackDirsPsr4 = array(); 49 | 50 | // PSR-0 51 | private $prefixesPsr0 = array(); 52 | private $fallbackDirsPsr0 = array(); 53 | 54 | private $useIncludePath = false; 55 | private $classMap = array(); 56 | private $classMapAuthoritative = false; 57 | private $missingClasses = array(); 58 | private $apcuPrefix; 59 | 60 | public function getPrefixes() 61 | { 62 | if (!empty($this->prefixesPsr0)) { 63 | return call_user_func_array('array_merge', $this->prefixesPsr0); 64 | } 65 | 66 | return array(); 67 | } 68 | 69 | public function getPrefixesPsr4() 70 | { 71 | return $this->prefixDirsPsr4; 72 | } 73 | 74 | public function getFallbackDirs() 75 | { 76 | return $this->fallbackDirsPsr0; 77 | } 78 | 79 | public function getFallbackDirsPsr4() 80 | { 81 | return $this->fallbackDirsPsr4; 82 | } 83 | 84 | public function getClassMap() 85 | { 86 | return $this->classMap; 87 | } 88 | 89 | /** 90 | * @param array $classMap Class to filename map 91 | */ 92 | public function addClassMap(array $classMap) 93 | { 94 | if ($this->classMap) { 95 | $this->classMap = array_merge($this->classMap, $classMap); 96 | } else { 97 | $this->classMap = $classMap; 98 | } 99 | } 100 | 101 | /** 102 | * Registers a set of PSR-0 directories for a given prefix, either 103 | * appending or prepending to the ones previously set for this prefix. 104 | * 105 | * @param string $prefix The prefix 106 | * @param array|string $paths The PSR-0 root directories 107 | * @param bool $prepend Whether to prepend the directories 108 | */ 109 | public function add($prefix, $paths, $prepend = false) 110 | { 111 | if (!$prefix) { 112 | if ($prepend) { 113 | $this->fallbackDirsPsr0 = array_merge( 114 | (array) $paths, 115 | $this->fallbackDirsPsr0 116 | ); 117 | } else { 118 | $this->fallbackDirsPsr0 = array_merge( 119 | $this->fallbackDirsPsr0, 120 | (array) $paths 121 | ); 122 | } 123 | 124 | return; 125 | } 126 | 127 | $first = $prefix[0]; 128 | if (!isset($this->prefixesPsr0[$first][$prefix])) { 129 | $this->prefixesPsr0[$first][$prefix] = (array) $paths; 130 | 131 | return; 132 | } 133 | if ($prepend) { 134 | $this->prefixesPsr0[$first][$prefix] = array_merge( 135 | (array) $paths, 136 | $this->prefixesPsr0[$first][$prefix] 137 | ); 138 | } else { 139 | $this->prefixesPsr0[$first][$prefix] = array_merge( 140 | $this->prefixesPsr0[$first][$prefix], 141 | (array) $paths 142 | ); 143 | } 144 | } 145 | 146 | /** 147 | * Registers a set of PSR-4 directories for a given namespace, either 148 | * appending or prepending to the ones previously set for this namespace. 149 | * 150 | * @param string $prefix The prefix/namespace, with trailing '\\' 151 | * @param array|string $paths The PSR-4 base directories 152 | * @param bool $prepend Whether to prepend the directories 153 | * 154 | * @throws \InvalidArgumentException 155 | */ 156 | public function addPsr4($prefix, $paths, $prepend = false) 157 | { 158 | if (!$prefix) { 159 | // Register directories for the root namespace. 160 | if ($prepend) { 161 | $this->fallbackDirsPsr4 = array_merge( 162 | (array) $paths, 163 | $this->fallbackDirsPsr4 164 | ); 165 | } else { 166 | $this->fallbackDirsPsr4 = array_merge( 167 | $this->fallbackDirsPsr4, 168 | (array) $paths 169 | ); 170 | } 171 | } elseif (!isset($this->prefixDirsPsr4[$prefix])) { 172 | // Register directories for a new namespace. 173 | $length = strlen($prefix); 174 | if ('\\' !== $prefix[$length - 1]) { 175 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 176 | } 177 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 178 | $this->prefixDirsPsr4[$prefix] = (array) $paths; 179 | } elseif ($prepend) { 180 | // Prepend directories for an already registered namespace. 181 | $this->prefixDirsPsr4[$prefix] = array_merge( 182 | (array) $paths, 183 | $this->prefixDirsPsr4[$prefix] 184 | ); 185 | } else { 186 | // Append directories for an already registered namespace. 187 | $this->prefixDirsPsr4[$prefix] = array_merge( 188 | $this->prefixDirsPsr4[$prefix], 189 | (array) $paths 190 | ); 191 | } 192 | } 193 | 194 | /** 195 | * Registers a set of PSR-0 directories for a given prefix, 196 | * replacing any others previously set for this prefix. 197 | * 198 | * @param string $prefix The prefix 199 | * @param array|string $paths The PSR-0 base directories 200 | */ 201 | public function set($prefix, $paths) 202 | { 203 | if (!$prefix) { 204 | $this->fallbackDirsPsr0 = (array) $paths; 205 | } else { 206 | $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; 207 | } 208 | } 209 | 210 | /** 211 | * Registers a set of PSR-4 directories for a given namespace, 212 | * replacing any others previously set for this namespace. 213 | * 214 | * @param string $prefix The prefix/namespace, with trailing '\\' 215 | * @param array|string $paths The PSR-4 base directories 216 | * 217 | * @throws \InvalidArgumentException 218 | */ 219 | public function setPsr4($prefix, $paths) 220 | { 221 | if (!$prefix) { 222 | $this->fallbackDirsPsr4 = (array) $paths; 223 | } else { 224 | $length = strlen($prefix); 225 | if ('\\' !== $prefix[$length - 1]) { 226 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 227 | } 228 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 229 | $this->prefixDirsPsr4[$prefix] = (array) $paths; 230 | } 231 | } 232 | 233 | /** 234 | * Turns on searching the include path for class files. 235 | * 236 | * @param bool $useIncludePath 237 | */ 238 | public function setUseIncludePath($useIncludePath) 239 | { 240 | $this->useIncludePath = $useIncludePath; 241 | } 242 | 243 | /** 244 | * Can be used to check if the autoloader uses the include path to check 245 | * for classes. 246 | * 247 | * @return bool 248 | */ 249 | public function getUseIncludePath() 250 | { 251 | return $this->useIncludePath; 252 | } 253 | 254 | /** 255 | * Turns off searching the prefix and fallback directories for classes 256 | * that have not been registered with the class map. 257 | * 258 | * @param bool $classMapAuthoritative 259 | */ 260 | public function setClassMapAuthoritative($classMapAuthoritative) 261 | { 262 | $this->classMapAuthoritative = $classMapAuthoritative; 263 | } 264 | 265 | /** 266 | * Should class lookup fail if not found in the current class map? 267 | * 268 | * @return bool 269 | */ 270 | public function isClassMapAuthoritative() 271 | { 272 | return $this->classMapAuthoritative; 273 | } 274 | 275 | /** 276 | * APCu prefix to use to cache found/not-found classes, if the extension is enabled. 277 | * 278 | * @param string|null $apcuPrefix 279 | */ 280 | public function setApcuPrefix($apcuPrefix) 281 | { 282 | $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null; 283 | } 284 | 285 | /** 286 | * The APCu prefix in use, or null if APCu caching is not enabled. 287 | * 288 | * @return string|null 289 | */ 290 | public function getApcuPrefix() 291 | { 292 | return $this->apcuPrefix; 293 | } 294 | 295 | /** 296 | * Registers this instance as an autoloader. 297 | * 298 | * @param bool $prepend Whether to prepend the autoloader or not 299 | */ 300 | public function register($prepend = false) 301 | { 302 | spl_autoload_register(array($this, 'loadClass'), true, $prepend); 303 | } 304 | 305 | /** 306 | * Unregisters this instance as an autoloader. 307 | */ 308 | public function unregister() 309 | { 310 | spl_autoload_unregister(array($this, 'loadClass')); 311 | } 312 | 313 | /** 314 | * Loads the given class or interface. 315 | * 316 | * @param string $class The name of the class 317 | * @return bool|null True if loaded, null otherwise 318 | */ 319 | public function loadClass($class) 320 | { 321 | if ($file = $this->findFile($class)) { 322 | includeFile($file); 323 | 324 | return true; 325 | } 326 | } 327 | 328 | /** 329 | * Finds the path to the file where the class is defined. 330 | * 331 | * @param string $class The name of the class 332 | * 333 | * @return string|false The path if found, false otherwise 334 | */ 335 | public function findFile($class) 336 | { 337 | // class map lookup 338 | if (isset($this->classMap[$class])) { 339 | return $this->classMap[$class]; 340 | } 341 | if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { 342 | return false; 343 | } 344 | if (null !== $this->apcuPrefix) { 345 | $file = apcu_fetch($this->apcuPrefix.$class, $hit); 346 | if ($hit) { 347 | return $file; 348 | } 349 | } 350 | 351 | $file = $this->findFileWithExtension($class, '.php'); 352 | 353 | // Search for Hack files if we are running on HHVM 354 | if (false === $file && defined('HHVM_VERSION')) { 355 | $file = $this->findFileWithExtension($class, '.hh'); 356 | } 357 | 358 | if (null !== $this->apcuPrefix) { 359 | apcu_add($this->apcuPrefix.$class, $file); 360 | } 361 | 362 | if (false === $file) { 363 | // Remember that this class does not exist. 364 | $this->missingClasses[$class] = true; 365 | } 366 | 367 | return $file; 368 | } 369 | 370 | private function findFileWithExtension($class, $ext) 371 | { 372 | // PSR-4 lookup 373 | $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; 374 | 375 | $first = $class[0]; 376 | if (isset($this->prefixLengthsPsr4[$first])) { 377 | $subPath = $class; 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { 379 | $subPath = substr($subPath, 0, $lastPos); 380 | $search = $subPath.'\\'; 381 | if (isset($this->prefixDirsPsr4[$search])) { 382 | $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); 383 | foreach ($this->prefixDirsPsr4[$search] as $dir) { 384 | if (file_exists($file = $dir . $pathEnd)) { 385 | return $file; 386 | } 387 | } 388 | } 389 | } 390 | } 391 | 392 | // PSR-4 fallback dirs 393 | foreach ($this->fallbackDirsPsr4 as $dir) { 394 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { 395 | return $file; 396 | } 397 | } 398 | 399 | // PSR-0 lookup 400 | if (false !== $pos = strrpos($class, '\\')) { 401 | // namespaced class name 402 | $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); 404 | } else { 405 | // PEAR-like class name 406 | $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; 407 | } 408 | 409 | if (isset($this->prefixesPsr0[$first])) { 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { 411 | if (0 === strpos($class, $prefix)) { 412 | foreach ($dirs as $dir) { 413 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 414 | return $file; 415 | } 416 | } 417 | } 418 | } 419 | } 420 | 421 | // PSR-0 fallback dirs 422 | foreach ($this->fallbackDirsPsr0 as $dir) { 423 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 424 | return $file; 425 | } 426 | } 427 | 428 | // PSR-0 include paths. 429 | if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { 430 | return $file; 431 | } 432 | 433 | return false; 434 | } 435 | } 436 | 437 | /** 438 | * Scope isolated include. 439 | * 440 | * Prevents access to $this/self from included files. 441 | */ 442 | function includeFile($file) 443 | { 444 | include $file; 445 | } 446 | -------------------------------------------------------------------------------- /vendor/composer/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) Nils Adermann, Jordi Boggiano 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is furnished 9 | to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /vendor/composer/autoload_classmap.php: -------------------------------------------------------------------------------- 1 | $baseDir . '/src/Admin.php', 10 | 'WPPluginDictator\\CLI' => $baseDir . '/src/CLI.php', 11 | 'WPPluginDictator\\Dictate' => $baseDir . '/src/Dictate.php', 12 | 'WPPluginDictator\\Utils' => $baseDir . '/src/Utils.php', 13 | ); 14 | -------------------------------------------------------------------------------- /vendor/composer/autoload_namespaces.php: -------------------------------------------------------------------------------- 1 | array($baseDir . '/src'), 10 | ); 11 | -------------------------------------------------------------------------------- /vendor/composer/autoload_real.php: -------------------------------------------------------------------------------- 1 | = 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); 27 | if ($useStaticLoader) { 28 | require_once __DIR__ . '/autoload_static.php'; 29 | 30 | call_user_func(\Composer\Autoload\ComposerStaticInitae2474ae5fa8b0c4bd3d248f5df2f730::getInitializer($loader)); 31 | } else { 32 | $map = require __DIR__ . '/autoload_namespaces.php'; 33 | foreach ($map as $namespace => $path) { 34 | $loader->set($namespace, $path); 35 | } 36 | 37 | $map = require __DIR__ . '/autoload_psr4.php'; 38 | foreach ($map as $namespace => $path) { 39 | $loader->setPsr4($namespace, $path); 40 | } 41 | 42 | $classMap = require __DIR__ . '/autoload_classmap.php'; 43 | if ($classMap) { 44 | $loader->addClassMap($classMap); 45 | } 46 | } 47 | 48 | $loader->register(true); 49 | 50 | return $loader; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /vendor/composer/autoload_static.php: -------------------------------------------------------------------------------- 1 | 11 | array ( 12 | 'WPPluginDictator\\' => 17, 13 | ), 14 | ); 15 | 16 | public static $prefixDirsPsr4 = array ( 17 | 'WPPluginDictator\\' => 18 | array ( 19 | 0 => __DIR__ . '/../..' . '/src', 20 | ), 21 | ); 22 | 23 | public static $classMap = array ( 24 | 'WPPluginDictator\\Admin' => __DIR__ . '/../..' . '/src/Admin.php', 25 | 'WPPluginDictator\\CLI' => __DIR__ . '/../..' . '/src/CLI.php', 26 | 'WPPluginDictator\\Dictate' => __DIR__ . '/../..' . '/src/Dictate.php', 27 | 'WPPluginDictator\\Utils' => __DIR__ . '/../..' . '/src/Utils.php', 28 | ); 29 | 30 | public static function getInitializer(ClassLoader $loader) 31 | { 32 | return \Closure::bind(function () use ($loader) { 33 | $loader->prefixLengthsPsr4 = ComposerStaticInitae2474ae5fa8b0c4bd3d248f5df2f730::$prefixLengthsPsr4; 34 | $loader->prefixDirsPsr4 = ComposerStaticInitae2474ae5fa8b0c4bd3d248f5df2f730::$prefixDirsPsr4; 35 | $loader->classMap = ComposerStaticInitae2474ae5fa8b0c4bd3d248f5df2f730::$classMap; 36 | 37 | }, null, ClassLoader::class); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /wp-plugin-dictator.php: -------------------------------------------------------------------------------- 1 | setup_constants(); 46 | self::$instance->includes(); 47 | self::$instance->run(); 48 | } 49 | 50 | /** 51 | * Action that fires after we are done setting things up in the plugin. Extensions of 52 | * this plugin should instantiate themselves on this hook to make sure the framework 53 | * is available before they do anything. 54 | * 55 | * @param object $instance Instance of the current WPPluginDictator class 56 | */ 57 | do_action( 'wp_plugin_dictator_init', self::$instance ); 58 | 59 | return self::$instance; 60 | 61 | } 62 | 63 | /** 64 | * Sets up the constants for the plugin to use 65 | * 66 | * @access private 67 | * @return void 68 | */ 69 | private function setup_constants() { 70 | 71 | // Plugin version. 72 | if ( ! defined( 'WP_PLUGIN_DICTATOR_VERSION' ) ) { 73 | define( 'WP_PLUGIN_DICTATOR_VERSION', '1.0.0' ); 74 | } 75 | 76 | // Plugin Folder Path. 77 | if ( ! defined( 'WP_PLUGIN_DICTATOR_PLUGIN_DIR' ) ) { 78 | define( 'WP_PLUGIN_DICTATOR_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 79 | } 80 | 81 | // Plugin Folder URL. 82 | if ( ! defined( 'WP_PLUGIN_DICTATOR_PLUGIN_URL' ) ) { 83 | define( 'WP_PLUGIN_DICTATOR_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 84 | } 85 | 86 | // Plugin Root File. 87 | if ( ! defined( 'WP_PLUGIN_DICTATOR_PLUGIN_FILE' ) ) { 88 | define( 'WP_PLUGIN_DICTATOR_PLUGIN_FILE', __FILE__ ); 89 | } 90 | 91 | } 92 | 93 | /** 94 | * Load the autoloaded files as well as the access functions 95 | * 96 | * @access private 97 | * @return void 98 | * @throws Exception 99 | */ 100 | private function includes() { 101 | 102 | if ( file_exists( WP_PLUGIN_DICTATOR_PLUGIN_DIR . 'vendor/autoload.php' ) ) { 103 | require_once( WP_PLUGIN_DICTATOR_PLUGIN_DIR . 'vendor/autoload.php' ); 104 | } else { 105 | throw new Exception( __( 'Could not find autoloader file to include all files', 'wp-plugin-dictator' ) ); 106 | } 107 | 108 | } 109 | 110 | /** 111 | * Instantiate the main classes we need for the plugin 112 | * 113 | * @access private 114 | * @return void 115 | */ 116 | private function run() { 117 | 118 | /** 119 | * Instantiate classes here 120 | */ 121 | $dictator = new \WPPluginDictator\Dictate(); 122 | $dictator->run(); 123 | 124 | add_action( 'init', function() { 125 | if ( is_admin() ) { 126 | $admin = new \WPPluginDictator\Admin(); 127 | $admin->setup(); 128 | } 129 | } ); 130 | 131 | if ( defined( 'WP_CLI' ) && true === WP_CLI ) { 132 | // Instantiate class for CLI commands here 133 | WP_CLI::add_command( 'plugin dictate', '\WPPluginDictator\CLI' ); 134 | } 135 | 136 | } 137 | 138 | } 139 | 140 | } 141 | 142 | /** 143 | * Function to instantiate the WPPluginDictator class 144 | * 145 | * @return Object|WPPluginDictator Instance of the WPPluginDictator object 146 | * @access public 147 | * @throws Exception 148 | */ 149 | function wp_plugin_dictator_init() { 150 | 151 | if ( did_action( 'plugins_loaded' ) ) { 152 | throw new Exception( __( 'This plugin needs to be dropped in the wp-content/mu-plugins folder to work properly', 'wp-plugin-dictator' ) ); 153 | } 154 | 155 | /** 156 | * Returns an instance of the WPPluginDictator class 157 | */ 158 | return \WPPluginDictator::instance(); 159 | 160 | } 161 | 162 | // Activate as early as possible, since this controls what plugins should/shouldn't be active, it needs to run before plugins are loaded. 163 | if ( ! wp_installing() ) { 164 | wp_plugin_dictator_init(); 165 | } 166 | --------------------------------------------------------------------------------