├── CHANGELOG.md
├── LICENSE
├── assets
├── css
│ ├── index.php
│ ├── style.css
│ └── style.min.css
├── examples
│ ├── blocked-robots.txt
│ ├── blogger-robots.txt
│ ├── default-robots.txt
│ ├── defaultalt-robots.txt
│ ├── google-robots.txt
│ ├── index.php
│ ├── open-robots.txt
│ └── wordpress-robots.txt
├── images
│ ├── index.php
│ └── sidebar_rate-plugin.gif
└── index.php
├── inc
├── autoload-classes.php
├── classes
│ ├── class-do-build-robotstxt.php
│ ├── class-do-delete-settings.php
│ ├── class-do-disable-website.php
│ ├── class-do-member-robotstxt-build.php
│ ├── class-do-network-robotstxt-build.php
│ ├── class-do-robotstxt-cleaner.php
│ ├── class-do-save-append-rules.php
│ ├── class-do-save-network-robotstxt.php
│ ├── class-do-save-preset-as-robotstxt.php
│ ├── class-get-robotstxt-rules.php
│ ├── class-msrobotstxtmanager.php
│ ├── class-option-manager.php
│ ├── class-plugin-activate.php
│ ├── class-plugin-admin-notices.php
│ ├── class-plugin-admin-post.php
│ ├── class-plugin-admin.php
│ ├── class-plugin-upgrade.php
│ ├── class-robotstxt.php
│ ├── class-trait-query-string.php
│ ├── class-trait-security-check.php
│ ├── class-translate.php
│ └── index.php
├── index.php
├── instantiate-admin-classes.php
├── instantiate-network-classes.php
├── instantiate-public-classes.php
└── templates
│ ├── cleaner.php
│ ├── footer.php
│ ├── header.php
│ ├── index.php
│ ├── network.php
│ ├── notice.php
│ ├── settings.php
│ ├── sidebar.php
│ └── upgrade.php
├── index.php
├── lang
├── index.php
└── multisite-robotstxt-manager.pot
├── multisite-robotstxt-manager.php
└── readme.txt
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | ## 3.1.0
4 |
5 | ### **2024-11-21- Feature**
6 |
7 | * Correct $output variable [#11](https://github.com/ChrisWinters/multisite-robotstxt-manager/pull/11)
8 | * Remove Freemius [#12](https://github.com/ChrisWinters/multisite-robotstxt-manager/pull/12)
9 | * Replace deprecated filter [#13](https://github.com/ChrisWinters/multisite-robotstxt-manager/issues/13)
10 | * WordPress 6.7.1 Tested
11 |
12 | ## 3.0.0
13 |
14 | ### **2020-04-11- Feature**
15 |
16 | * Freemius upgrade
17 | * Activation issue [#8](https://github.com/ChrisWinters/multisite-robotstxt-manager/issues/8)
18 | * WordPress 5.4 Tested
19 |
20 | ## 2.1.1
21 |
22 | ### **2020-01-11- Hotfix**
23 |
24 | * Modified how robots.txt file is generated within class-robotstxt.php
25 |
26 | ## 2.1.0
27 |
28 | ### **2019-10-06 - Feature**
29 |
30 | * Added website override option to ignore network robots.txt file
31 |
32 | ## 2.0.4
33 |
34 | ### **2019-08-28 - Hotfix**
35 |
36 | * Removed Freemius nag notice.
37 |
38 | ## 2.0.3
39 |
40 | ### **2019-08-22 - Hotfix**
41 |
42 | * Corrected class-do-build-robotstxt.php array pairs for class-option-manager.php
43 | * Corrected class-option-manager.php to correctly checking for array key before building the array
44 | * Moved robotstxt build call in class-do-save-append-rules.php to fire only if the setting was updated
45 | * Added {APPEND_WEBSITE_ROBOTSTXT} to open robots.txt file within class-do-save-preset-as-robotstxt.php
46 |
47 | ## 2.0.2
48 |
49 | ### **2019-08-07 - Hotfix**
50 |
51 | * Removed plugin-activation level upgrade in favor of manual upgrade
52 | * Moved admin/network/public class includes into plugins_loaded hook
53 | * Modified class-translate.php to use new translation call format
54 | * Modified sidebar hardcoded images to use plugin_dir_url()
55 | * Modified plugin settings upgrade message for new installs
56 | * Corrected network delete all settings to correctly delete all settings
57 | * Corrected function call in class-do-network-robotstxt-build.php
58 | * Corrected function call in class-do-robotstxt-cleaner.php
59 | * Corrected bump.js gulp task
60 |
61 | ## 2.0.1
62 |
63 | ### **2019-07-25 - Hotfix**
64 |
65 | * Created manual upgrade and delete old settings notice.
66 |
67 | ## 2.0.0
68 |
69 | ### **2019-07-22 - Release**
70 |
71 | * Tested: Wordpress Version 5.2.2
72 | * Major code base upgrade
73 | * Migrated settings to single option
74 |
75 | ## 1.0.12
76 |
77 | ### **2017-9-6 - Hotfix**
78 |
79 | * Tested: Wordpress Version 4.8
80 | * Changed: Network & Admin Area Plugin Update Notice Handler.
81 | * Fixed: Remove Rewrite Rule Flush After Correcting Rewrite Rules.
82 |
83 | ## 1.0.11
84 |
85 | ### **2017-24-4 - Hotfix**
86 |
87 | * Added: Added more Sitemap filenames to check/build for.
88 | * Changed: Sitemap check/build, added rewrite rule & physical file checks if fopen is not enabled.
89 |
90 | ## 1.0.10
91 |
92 | ### **2017-23-4 - Hotfix**
93 |
94 | * Tested: Wordpress Version 4.7.4
95 | * Changed: Review/Rating URL within templates/sidebar.php
96 | * Fixed: Cleaner option name checks, using previous version names.
97 | * Fixed: Cleaner rewrite_rule to delete/update the option when missing the robots.txt array.
98 |
99 | ## 1.0.9
100 |
101 | * Fixed: Bad method call in class-cleaner.php.
102 | * Fixed: Multiple incorrect update_option formats.
103 | * Fixed: Network Robots.txt now saves when published [#5](https://github.com/ChrisWinters/multisite-robotstxt-manager/issues/5)
104 | * Fixed: Removed append marker, if no append rules found.
105 | * Fixed: Wrapped is_writable() check to physical robots.txt removal.
106 | * Change: Option names for cleaner, appended cleaner_.
107 | * Change: Modified update success/fail messages.
108 | * Change: Deleted uninstall.php [#6](https://github.com/ChrisWinters/multisite-robotstxt-manager/issues/6)
109 |
110 | ## 1.0.8
111 |
112 | * New plugin structure/files, using the same option names.
113 | * Added: New tab "Cleaner" to the Network Admin area.
114 | * Added: Two stage cleaning process - check & clean.
115 | * Added: Check for a physical robots.txt file.
116 | * Added: Check for missing robots.txt file rewrite rule.
117 | * Added: Network tab to Websites for quick access to plugin admin within the Network.
118 | * Added: Option to disable network robots.txt file on websites, allowing for full customization of websites robots.txt file.
119 | * Change: Plugin admin areas to be more visually friendly.
120 | * Moved: Screenshots/header/thumbnail images into the svn/assets folder.
121 |
122 | ## 1.0.7
123 |
124 | * Bug: Fixed bad calls from helper class causing options not saving for each site. Thanks https://github.com/benjaminniess
125 |
126 | ## 1.0.6
127 |
128 | * Bug: Corrected class_helper->getSitemapUrl() - printing "No Sitemap Found" in robots.txt files
129 | * Bug: Moved class_admin->updateNetwork()->throwMessage() outside of foreach when updating the network
130 | * Change: templates/home.php to display No Sitemap Found within input field
131 |
132 | ## 1.0.5
133 |
134 | * Modified class_helper->getSitemapUrl(): added get_option( 'siteurl' ) check for sitemap url
135 | * Corrected commented out redirect action
136 | * Corrected marketup in robots.txt file, again.
137 | * Added final public to class_presets methods
138 |
139 | ## 1.0.4
140 |
141 | * Add options to update the full network or only blogs the admin is a user of
142 | * Added message for missing sitemap.xml files within website plugin admin
143 | * Added user notice & error message to all form actions
144 | * Corrected readme.txt file formating
145 | * Corrected notice locations for all 3 detection rules
146 | * Corrected network admin showing website admin status messages
147 | * Corrected message when updating network from disabled network
148 | * Corrected missing new line in the preset WordPress Limited option
149 | * Adjusted disable/delete input names to be code-reader friendly
150 | * Removed class_core.php, functions moved to plugin root
151 | * Commented out $rewrite_rule check/update, until new solution is found
152 |
153 | ## 1.0.3
154 |
155 | * Moved upgrade process outside of activation method, into unique class
156 | * Added message/method to detect and replace old plugin data with new data
157 | * Re-added old robots.txt plugin detection and cleaning option
158 | * Re-added bad rewrite rule detection and cleaning option
159 |
160 | ## 1.0.2
161 |
162 | * Upgrade Bug Corrected
163 | * Changed how Extention loads in
164 | * Adjusted Extension calls throughout plugin
165 | * Adjusted plugin activation order for detecting old plugin options
166 | * Corrected static function calls for register_activation_hook
167 | * Added feature to copy old sitemap url to new append option
168 |
169 | ## 1.0.1
170 |
171 | * Because SVN sucks!
172 |
173 | ## 1.0.0
174 |
175 | * Major rebuild, all files recreated, new code
176 | * Set network robots.txt file as global file
177 | * Created append rules for Websites
178 | * Improved Sitemap Detection
179 | * Added Theme & Upload Path Support
180 | * Adjusted admin area layout and look
181 | * Adjusted how Pro Extension adapts in
182 | * Expanded automation features
183 |
184 | ## 0.4.0
185 |
186 | * Major rebuild
187 | * Modified how and when the sitemap urls are created.
188 | * Created top-level domain array for sitemap url breakdown.
189 | * Removed network map checks due to alt setup methods.
190 | * Update preset robots.txt files and create 2 new styles.
191 | * Rebuilt all options to use array format.
192 | * Renamed classes and functions.
193 | * Added better sanitization and escaping throughout.
194 | * Adjusted how pro extension integrates in.
195 | * Modified admin html/css to work better for mobile.
196 | * Removed a few pounds of code.
197 | * Improved help text throughout.
198 | * Improved error checking.
199 | * Adjusted install/uninstall functions for non-network installs.
200 | * Merged network admin and website admin template.
201 | * Add old robots.txt plugin detection and cleaning option.
202 |
203 | ## 0.3.1
204 |
205 | * Created website admin areas.
206 | * Added is_user_member_of_blog function for super admins.
207 |
208 | ## 0.3.0
209 |
210 | * Modified add_submenu_page calls.
211 | * Modified DB prepare() statements.
212 | * Structure change to make room for automation feature.
213 | * Cleaned undefined index errors.
214 | * Ran PHP Debug and WP Debug and removed related errors.
215 |
216 | ## 0.2.2x
217 |
218 | * Modified add_submenu_page calls.
219 | * Modified DB prepare() statements.
220 | * Structure change to make room for automation feature.
221 |
222 | ## 0.2.1
223 |
224 | * Made robots.txt file display when a Website within a directory (domain.com/domain-path) is called.
225 | * Added is_network_admin() and $_SERVER script checks around extra links function.
226 | * Cleaned up activation & deactivation hook calls to only be called when executed.
227 | * Added do_action( 'do_robotstxt' ); call after header call of robots.txt display.
228 | * Adjusted robots.txt display to use public/private blog feature correctly.
229 | * Removed is_user_member_of_blog() check around add_submenu_page() calls.
230 | * Added $_GET['page'] :: "ms_robotstxt.php" wrap around tab display call.
231 | * Improved sitemap structure url output with various domain structures.
232 | * Added current_user_can() && is_super_admin() check to uninstall.php
233 | * Added / adjusted wp_nonce_field and check_admin_referer calls.
234 | * Created second set of tab links at the bottom of plugin admin.
235 | * Cleaned up robots.txt display class - add_filter call.
236 | * Setup better error handling on all form submits.
237 | * Added in version check and file check calls.
238 | * Improved sitemap structure function.
239 | * More comments.
240 |
241 | ## 0.2.0
242 |
243 | * Made the site dropdown list populate in a new way, and list site names insted of domains.
244 | * Added sitemap option, url, and structure to default robots.txt, per site, and pre-sets.
245 | * Adjusted all post types and preset values, and option arrays to use sitemap structure.
246 | * Adjusted default option for websites robots.txt to store data within an array.
247 | * Created a new sitemap option to store sitemap data at the Website level.
248 | * Adusted, cleaned html and corrected typos within admin area template.
249 | * Adjusted default robots.txt option to store data within an array.
250 | * Created instructions for the Sitemap URL Structure feature.
251 | * Adjusted robots.txt display to include sitemap urls.
252 | * Adjusted uninstall.php to use new option names.
253 | * Removed transient cache and related db calls.
254 | * New screenshot file and readme.txt updated.
255 | * Updated WordPress Function References.
256 | * Added non-network check on install.
257 | * Serialize proper option data.
258 |
259 | ## 0.1.1
260 |
261 | * Replaced action do_robots with filter robots_txt at call.
262 | * Removed ob_gzhandler
263 |
264 | ## 0.1
265 |
266 | * Created March 08, 2012
267 |
--------------------------------------------------------------------------------
/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 |
635 | Copyright (C)
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 | Copyright (C)
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 | .
--------------------------------------------------------------------------------
/assets/css/index.php:
--------------------------------------------------------------------------------
1 |
8 | * @license GNU GPLv3
9 | * @link /LICENSE
10 | */
11 |
12 | namespace MsRobotstxtManager;
13 |
14 | if ( false === defined( 'ABSPATH' ) ) {
15 | exit;
16 | }
17 |
18 | /**
19 | * Register Classes
20 | *
21 | * @param string $class Loaded Classes.
22 | */
23 | function ms_robotstxt_manager_register_classes( $class ) {
24 | // Namespace Prefix.
25 | $prefix = 'MsRobotstxtManager\\';
26 |
27 | // Move To Next Rgistered autoloader.
28 | $len = strlen( $prefix );
29 | if ( strncmp( $prefix, $class, $len ) !== 0 ) {
30 | return;
31 | }
32 |
33 | // Build Class Name.
34 | $relative_class = strtolower( str_replace( '_', '-', substr( $class, $len ) ) );
35 |
36 | // Replace Dir Separators and Replace Namespace with Base Dir.
37 | $file = MS_ROBOTSTXT_MANAGER_DIR . '/inc/classes/class-' . str_replace( '\\', '/', $relative_class ) . '.php';
38 |
39 | // Include File.
40 | if ( true === file_exists( $file ) ) {
41 | require $file;
42 | }
43 | }//end ms_robotstxt_manager_register_classes()
44 |
45 | spl_autoload_register( 'MsRobotstxtManager\ms_robotstxt_manager_register_classes' );
46 |
--------------------------------------------------------------------------------
/inc/classes/class-do-build-robotstxt.php:
--------------------------------------------------------------------------------
1 |
8 | * @license GNU GPLv3
9 | * @link /LICENSE
10 | */
11 |
12 | namespace MsRobotstxtManager;
13 |
14 | if ( false === defined( 'ABSPATH' ) ) {
15 | exit;
16 | }
17 |
18 | /**
19 | * Build Network Website Robots.txt File
20 | */
21 | final class Do_Build_Robotstxt {
22 | /**
23 | * Option_Manager Class.
24 | *
25 | * @var object
26 | */
27 | public $option_manager = [];
28 |
29 |
30 | /**
31 | * Setup Class
32 | *
33 | * @param object $option_manager Option_Manager.
34 | */
35 | public function __construct( $option_manager = [] ) {
36 | if ( true === empty( $option_manager ) ) {
37 | return;
38 | }
39 |
40 | $this->option_manager = $option_manager;
41 | }//end __construct()
42 |
43 |
44 | /**
45 | * Build & Save Robots.txt File
46 | *
47 | * @param int $site_id Network Site ID.
48 | */
49 | public function init( $site_id = '' ) {
50 | if ( true === empty( $this->option_manager ) ) {
51 | return;
52 | }
53 |
54 | $site_id = $this->get_site_id( $site_id );
55 |
56 | if ( true !== empty( $site_id ) ) {
57 | /*
58 | * Switch the current blog.
59 | * https://developer.wordpress.org/reference/functions/switch_to_blog/
60 | */
61 | switch_to_blog( $site_id );
62 | }
63 |
64 | $website_option = $this->option_manager->get_option();
65 |
66 | $network_robotstxt_file = $this->option_manager->get_site_option();
67 |
68 | // Return Default WordPress Robots.txt File.
69 | if ( true === empty( $network_robotstxt_file['robotstxt'] ) ) {
70 | return;
71 | }
72 |
73 | $append_rules = ( true !== empty( $website_option['append'] ) ) ? $website_option['append'] : '';
74 | $robotstxt_file = $this->replace_append_rules( $network_robotstxt_file['robotstxt'], $append_rules );
75 |
76 | $this->update_robotstxt( $website_option, $robotstxt_file );
77 |
78 | if ( true !== empty( $site_id ) ) {
79 | /*
80 | * Restore the current blog, after calling switch_to_blog.
81 | * https://developer.wordpress.org/reference/functions/restore_current_blog/
82 | */
83 | restore_current_blog();
84 | }
85 | }//end init()
86 |
87 |
88 | /**
89 | * Get Current Site ID
90 | *
91 | * @param int $site_id Network Site ID.
92 | *
93 | * @return int/empty
94 | */
95 | private function get_site_id( $site_id = '' ) {
96 | /*
97 | * Whether the current request is for the network administrative interface.
98 | * https://developer.wordpress.org/reference/functions/is_network_admin/
99 | */
100 | if ( true === empty( $site_id ) && true !== is_network_admin() ) {
101 | /*
102 | * Retrieve the current site ID.
103 | * https://developer.wordpress.org/reference/functions/get_current_blog_id/
104 | */
105 | $site_id = get_current_blog_id();
106 | }
107 |
108 | return $site_id;
109 | }//end get_site_id()
110 |
111 |
112 | /**
113 | * Maybe Replace Append Rules
114 | *
115 | * @param string $network_robotstxt Network Robots.txt File.
116 | * @param string $append_rules Website Append Rules.
117 | *
118 | * @return string
119 | */
120 | private function replace_append_rules( $network_robotstxt, $append_rules = '' ) {
121 | if ( true !== empty( $append_rules ) ) {
122 | // Append Rules Found.
123 | $robotstxt_file = str_replace( '{APPEND_WEBSITE_ROBOTSTXT}', $append_rules, $network_robotstxt );
124 | } else {
125 | // No Append Rules.
126 | $robotstxt_file = str_replace( '{APPEND_WEBSITE_ROBOTSTXT}', '', $network_robotstxt );
127 | }
128 |
129 | return $robotstxt_file;
130 | }//end replace_append_rules()
131 |
132 |
133 | /**
134 | * Maybe Update Website Robots.txt File
135 | *
136 | * @param array $website_option Current Plugin Option Data.
137 | * @param string $robotstxt_file Robots.txt File To Save.
138 | */
139 | private function update_robotstxt( $website_option = '', $robotstxt_file = '' ) {
140 | if ( true === empty( $website_option ) ) {
141 | $website_option = [];
142 | }
143 |
144 | if ( true === is_array( $website_option ) && true === array_key_exists( 'robotstxt', $website_option ) ) {
145 | unset( $website_option['robotstxt'] );
146 | }
147 |
148 | $this->option_manager->update_option( array_merge( [ 'robotstxt' => $robotstxt_file ], $website_option ) );
149 | }//end update_robotstxt()
150 | }//end class
151 |
--------------------------------------------------------------------------------
/inc/classes/class-do-delete-settings.php:
--------------------------------------------------------------------------------
1 |
8 | * @license GNU GPLv3
9 | * @link /LICENSE
10 | */
11 |
12 | namespace MsRobotstxtManager;
13 |
14 | if ( false === defined( 'ABSPATH' ) ) {
15 | exit;
16 | }
17 |
18 | use MsRobotstxtManager\Trait_Security_Check as TraitSecurityCheck;
19 | use MsRobotstxtManager\Plugin_Admin_Notices as PluginAdminNotices;
20 | use MsRobotstxtManager\Option_Manager as OptionManager;
21 |
22 | /**
23 | * Delete All Plugin Settings
24 | */
25 | final class Do_Delete_Settings {
26 | use TraitSecurityCheck;
27 |
28 | /**
29 | * Plugin Admin Post Object.
30 | *
31 | * @var array
32 | */
33 | public $post_object = [];
34 |
35 | /**
36 | * Post Action To Take.
37 | *
38 | * @var string
39 | */
40 | public $post_action = [];
41 |
42 | /**
43 | * Option_Manager Class.
44 | *
45 | * @var object
46 | */
47 | public $option_manager = [];
48 |
49 | /**
50 | * Plugin_Admin_Notices Class
51 | *
52 | * @var object
53 | */
54 | public $admin_notices = [];
55 |
56 |
57 | /**
58 | * Setup Class
59 | *
60 | * @param array $post_object Cleaned Post Object.
61 | */
62 | public function __construct( $post_object = [] ) {
63 | if ( true === empty( $post_object ) || true === empty( $post_object['action'] ) ) {
64 | return;
65 | }
66 |
67 | $this->post_object = $post_object;
68 | $this->post_action = $post_object['action'];
69 | $this->option_manager = new OptionManager();
70 | $this->admin_notices = new PluginAdminNotices();
71 | }//end __construct()
72 |
73 |
74 | /**
75 | * Init Update Action
76 | */
77 | public function init() {
78 | if ( true === empty( $this->post_object ) ) {
79 | return;
80 | }
81 |
82 | /*
83 | * Fires as an admin screen or script is being initialized.
84 | * https://developer.wordpress.org/reference/hooks/admin_init/
85 | */
86 | add_action(
87 | 'admin_init',
88 | [
89 | $this,
90 | 'update',
91 | ]
92 | );
93 | }//end init()
94 |
95 |
96 | /**
97 | * Security Check & Update On Action
98 | */
99 | public function update() {
100 | $this->security_check();
101 |
102 | // Set Disable Marker For Website.
103 | if ( 'delete' === $this->post_action ) {
104 | $this->do_delete();
105 | }
106 | }//end update()
107 |
108 |
109 | /**
110 | * Init Delete
111 | */
112 | private function do_delete() {
113 | /*
114 | * Retrieves a list of sites matching requested arguments.
115 | * https://developer.wordpress.org/reference/functions/get_sites/
116 | */
117 | foreach ( get_sites() as $website ) {
118 | /*
119 | * Switch the current blog.
120 | * https://developer.wordpress.org/reference/functions/switch_to_blog/
121 | */
122 | switch_to_blog( $website->blog_id );
123 |
124 | $this->option_manager->delete_option();
125 |
126 | /*
127 | * Restore the current blog, after calling switch_to_blog.
128 | * https://developer.wordpress.org/reference/functions/restore_current_blog/
129 | */
130 | restore_current_blog();
131 | }
132 |
133 | $this->option_manager->delete_site_option();
134 |
135 | if ( true === empty( $this->option_manager->get_option() ) && true === empty( $this->option_manager->get_site_option() ) ) {
136 | $this->admin_notices->add_notice( 'success', 'delete_success', 'network' );
137 | }
138 | }//end do_delete()
139 | }//end class
140 |
--------------------------------------------------------------------------------
/inc/classes/class-do-disable-website.php:
--------------------------------------------------------------------------------
1 |
8 | * @license GNU GPLv3
9 | * @link /LICENSE
10 | */
11 |
12 | namespace MsRobotstxtManager;
13 |
14 | if ( false === defined( 'ABSPATH' ) ) {
15 | exit;
16 | }
17 |
18 | use MsRobotstxtManager\Trait_Security_Check as TraitSecurityCheck;
19 | use MsRobotstxtManager\Plugin_Admin_Notices as PluginAdminNotices;
20 | use MsRobotstxtManager\Option_Manager as OptionManager;
21 |
22 | /**
23 | * Set Disable Marker For Website
24 | */
25 | final class Do_Disable_Website {
26 | use TraitSecurityCheck;
27 |
28 | /**
29 | * Plugin Admin Post Object.
30 | *
31 | * @var array
32 | */
33 | public $post_object = [];
34 |
35 | /**
36 | * Post Action To Take.
37 | *
38 | * @var string
39 | */
40 | public $post_action = [];
41 |
42 | /**
43 | * Option_Manager Class.
44 | *
45 | * @var object
46 | */
47 | public $option_manager = [];
48 |
49 | /**
50 | * Plugin_Admin_Notices Class
51 | *
52 | * @var object
53 | */
54 | public $admin_notices = [];
55 |
56 |
57 | /**
58 | * Setup Class
59 | *
60 | * @param array $post_object Cleaned Post Object.
61 | */
62 | public function __construct( $post_object = [] ) {
63 | if ( true === empty( $post_object ) || true === empty( $post_object['action'] ) ) {
64 | return;
65 | }
66 |
67 | $this->post_object = $post_object;
68 | $this->post_action = $post_object['action'];
69 | $this->option_manager = new OptionManager();
70 | $this->admin_notices = new PluginAdminNotices();
71 | }//end __construct()
72 |
73 |
74 | /**
75 | * Init Update Action
76 | */
77 | public function init() {
78 | if ( true === empty( $this->post_object ) ) {
79 | return;
80 | }
81 |
82 | /*
83 | * Fires as an admin screen or script is being initialized.
84 | * https://developer.wordpress.org/reference/hooks/admin_init/
85 | */
86 | add_action(
87 | 'admin_init',
88 | [
89 | $this,
90 | 'update',
91 | ]
92 | );
93 | }//end init()
94 |
95 |
96 | /**
97 | * Security Check & Update On Action
98 | */
99 | public function update() {
100 | $this->security_check();
101 |
102 | // Set Disable Marker For Website.
103 | if ( 'disable' === $this->post_action ) {
104 | $this->disable_website();
105 | }
106 | }//end update()
107 |
108 |
109 | /**
110 | * Set Disable Marker For Website
111 | */
112 | private function disable_website() {
113 | $this->option_manager->update_setting( 'disable', true );
114 |
115 | if ( true === $this->option_manager->get_setting( 'disable' ) ) {
116 | $this->admin_notices->add_notice( 'success', 'disable_success' );
117 | }
118 | }//end disable_website()
119 | }//end class
120 |
--------------------------------------------------------------------------------
/inc/classes/class-do-member-robotstxt-build.php:
--------------------------------------------------------------------------------
1 |
8 | * @license GNU GPLv3
9 | * @link /LICENSE
10 | */
11 |
12 | namespace MsRobotstxtManager;
13 |
14 | if ( false === defined( 'ABSPATH' ) ) {
15 | exit;
16 | }
17 |
18 | use MsRobotstxtManager\Trait_Security_Check as TraitSecurityCheck;
19 | use MsRobotstxtManager\Plugin_Admin_Notices as PluginAdminNotices;
20 | use MsRobotstxtManager\Do_Build_Robotstxt as DoBuildRobotstxt;
21 | use MsRobotstxtManager\Option_Manager as OptionManager;
22 |
23 | /**
24 | * Build Robots.txt File Across All Member Sites.
25 | */
26 | final class Do_Member_Robotstxt_Build {
27 | use TraitSecurityCheck;
28 |
29 | /**
30 | * Plugin Admin Post Object.
31 | *
32 | * @var array
33 | */
34 | public $post_object = array();
35 |
36 | /**
37 | * Post Action To Take.
38 | *
39 | * @var string
40 | */
41 | public $post_action = array();
42 |
43 | /**
44 | * Option_Manager Class.
45 | *
46 | * @var object
47 | */
48 | public $option_manager = array();
49 |
50 | /**
51 | * Plugin_Admin_Notices Class
52 | *
53 | * @var object
54 | */
55 | public $admin_notices = array();
56 |
57 | /**
58 | * Do_Build_Robotstxt Class
59 | *
60 | * @var object
61 | */
62 | public $build_robotstxt = array();
63 |
64 |
65 | /**
66 | * Setup Class
67 | *
68 | * @param array $post_object Cleaned Post Object.
69 | */
70 | public function __construct( $post_object = array() ) {
71 | if ( true === empty( $post_object ) || true === empty( $post_object['action'] ) ) {
72 | return;
73 | }
74 |
75 | $this->post_object = $post_object;
76 | $this->post_action = $post_object['action'];
77 | $this->option_manager = new OptionManager();
78 | $this->admin_notices = new PluginAdminNotices();
79 | $this->build_robotstxt = new DoBuildRobotstxt( $this->option_manager );
80 | }//end __construct()
81 |
82 |
83 | /**
84 | * Init Update Action
85 | */
86 | public function init() {
87 | if ( true === empty( $this->post_object ) ) {
88 | return;
89 | }
90 |
91 | /*
92 | * Fires as an admin screen or script is being initialized.
93 | * https://developer.wordpress.org/reference/hooks/admin_init/
94 | */
95 | add_action( 'admin_init', array( $this, 'update' ) );
96 | }//end init()
97 |
98 |
99 | /**
100 | * Security Check & Update On Action
101 | */
102 | public function update() {
103 | $this->security_check();
104 | // Network Member Sites Robots.txt Build.
105 | if ( 'member' === $this->post_action ) {
106 | $this->member_robotstxt_build();
107 | }
108 | }//end update()
109 |
110 |
111 | /**
112 | * Network Member Sites Robots.txt Build
113 | */
114 | private function member_robotstxt_build() {
115 | if ( true === empty( $this->post_object ) || true === empty( $this->admin_notices ) ) {
116 | return;
117 | }
118 | $message = false;
119 |
120 | if ( true !== empty( $this->post_object ) && true !== empty( $this->post_object['robotstxt'] ) ) {
121 | $this->option_manager->update_site_option( 'robotstxt', $this->post_object['robotstxt'] );
122 | $message = true;
123 | }
124 |
125 | if ( true !== empty( $this->post_object ) && true === empty( $this->post_object['robotstxt'] ) ) {
126 | $this->option_manager->delete_site_option();
127 | $message = true;
128 | }
129 |
130 | // Current Admin User.
131 | $current_user = wp_get_current_user();
132 | $this_admin_user = $current_user->ID;
133 |
134 | /*
135 | * Get the sites a user belongs to.
136 | * https://developer.wordpress.org/reference/functions/get_blogs_of_user/
137 | */
138 | $members_blogs = get_blogs_of_user( $this_admin_user );
139 |
140 | // Update Allowed Blogs.
141 | foreach ( $members_blogs as $member ) {
142 | /*
143 | * Switch the current blog.
144 | * https://developer.wordpress.org/reference/functions/switch_to_blog/
145 | */
146 | switch_to_blog( $member->userblog_id );
147 | // Build Robots.txt Files.
148 | $this->build_robotstxt->init( $member->userblog_id );
149 |
150 | /*
151 | * Restore the current blog, after calling switch_to_blog.
152 | * https://developer.wordpress.org/reference/functions/restore_current_blog/
153 | */
154 | restore_current_blog();
155 | }
156 |
157 | if ( true === $message ) {
158 | $this->admin_notices->add_notice( 'success', 'member_updated', 'network' );
159 | }
160 | }
161 | }//end class
162 |
--------------------------------------------------------------------------------
/inc/classes/class-do-network-robotstxt-build.php:
--------------------------------------------------------------------------------
1 |
8 | * @license GNU GPLv3
9 | * @link /LICENSE
10 | */
11 |
12 | namespace MsRobotstxtManager;
13 |
14 | if ( false === defined( 'ABSPATH' ) ) {
15 | exit;
16 | }
17 |
18 | use MsRobotstxtManager\Trait_Security_Check as TraitSecurityCheck;
19 | use MsRobotstxtManager\Plugin_Admin_Notices as PluginAdminNotices;
20 | use MsRobotstxtManager\Do_Build_Robotstxt as DoBuildRobotstxt;
21 | use MsRobotstxtManager\Option_Manager as OptionManager;
22 |
23 | /**
24 | * Build Robots.txt File Across All Network Sites.
25 | */
26 | final class Do_Network_Robotstxt_Build {
27 | use TraitSecurityCheck;
28 |
29 | /**
30 | * Plugin Admin Post Object.
31 | *
32 | * @var array
33 | */
34 | public $post_object = array();
35 |
36 | /**
37 | * Post Action To Take.
38 | *
39 | * @var string
40 | */
41 | public $post_action = array();
42 |
43 | /**
44 | * Option_Manager Class.
45 | *
46 | * @var object
47 | */
48 | public $option_manager = array();
49 |
50 | /**
51 | * Plugin_Admin_Notices Class
52 | *
53 | * @var object
54 | */
55 | public $admin_notices = array();
56 |
57 | /**
58 | * Do_Build_Robotstxt Class
59 | *
60 | * @var object
61 | */
62 | public $build_robotstxt = array();
63 |
64 |
65 | /**
66 | * Setup Class
67 | *
68 | * @param array $post_object Cleaned Post Object.
69 | */
70 | public function __construct( $post_object = array() ) {
71 | if ( true === empty( $post_object ) || true === empty( $post_object['action'] ) ) {
72 | return;
73 | }
74 |
75 | $this->post_object = $post_object;
76 | $this->post_action = $post_object['action'];
77 | $this->option_manager = new OptionManager();
78 | $this->admin_notices = new PluginAdminNotices();
79 | $this->build_robotstxt = new DoBuildRobotstxt( $this->option_manager );
80 | }//end __construct()
81 |
82 |
83 | /**
84 | * Init Update Action
85 | */
86 | public function init() {
87 | if ( true === empty( $this->post_object ) ) {
88 | return;
89 | }
90 |
91 | /*
92 | * Fires as an admin screen or script is being initialized.
93 | * https://developer.wordpress.org/reference/hooks/admin_init/
94 | */
95 | add_action( 'admin_init', array( $this, 'update' ) );
96 | }//end init()
97 |
98 |
99 | /**
100 | * Security Check & Update On Action
101 | */
102 | public function update() {
103 | $this->security_check();
104 |
105 | // All Network Sites Robots.txt Builds.
106 | if ( 'network' === $this->post_action ) {
107 | $this->network_robosttxt_build();
108 | }
109 | }//end update()
110 |
111 |
112 | /**
113 | * All Network Sites Robots.txt Builds
114 | */
115 | private function network_robosttxt_build() {
116 | if ( true === empty( $this->post_object ) || true === empty( $this->admin_notices ) ) {
117 | return;
118 | }
119 |
120 | $message = false;
121 |
122 | if ( true !== empty( $this->post_object ) && true !== empty( $this->post_object['robotstxt'] ) ) {
123 | $this->option_manager->update_site_option( 'robotstxt', $this->post_object['robotstxt'] );
124 | $message = true;
125 | }
126 |
127 | if ( true !== empty( $this->post_object ) && true === empty( $this->post_object['robotstxt'] ) ) {
128 | $this->option_manager->delete_site_option();
129 | $message = true;
130 | }
131 |
132 | /*
133 | * Retrieves a list of sites matching requested arguments.
134 | * https://developer.wordpress.org/reference/functions/get_sites/
135 | */
136 | foreach ( get_sites() as $website ) {
137 | /*
138 | * Switch the current blog.
139 | * https://developer.wordpress.org/reference/functions/switch_to_blog/
140 | */
141 | switch_to_blog( $website->blog_id );
142 |
143 | // Build Robots.txt Files.
144 | $this->build_robotstxt->init( $website->blog_id );
145 |
146 | /*
147 | * Restore the current blog, after calling switch_to_blog.
148 | * https://developer.wordpress.org/reference/functions/restore_current_blog/
149 | */
150 | restore_current_blog();
151 | }
152 |
153 | if ( true === $message ) {
154 | $this->admin_notices->add_notice( 'success', 'network_updated', 'network' );
155 | }
156 | }
157 | }//end class
158 |
--------------------------------------------------------------------------------
/inc/classes/class-do-robotstxt-cleaner.php:
--------------------------------------------------------------------------------
1 |
8 | * @license GNU GPLv3
9 | * @link /LICENSE
10 | */
11 |
12 | namespace MsRobotstxtManager;
13 |
14 | if ( false === defined( 'ABSPATH' ) ) {
15 | exit;
16 | }
17 |
18 | use MsRobotstxtManager\Trait_Security_Check as TraitSecurityCheck;
19 | use MsRobotstxtManager\Plugin_Admin_Notices as PluginAdminNotices;
20 | use MsRobotstxtManager\Option_Manager as OptionManager;
21 |
22 | /**
23 | * Robots.txt Cleaner Rules & Actions
24 | */
25 | final class Do_Robotstxt_Cleaner {
26 | use TraitSecurityCheck;
27 |
28 | /**
29 | * Plugin Admin Post Object.
30 | *
31 | * @var array
32 | */
33 | public $post_object = [];
34 |
35 | /**
36 | * Post Action To Take.
37 | *
38 | * @var string
39 | */
40 | public $post_action = [];
41 |
42 | /**
43 | * Option_Manager Class.
44 | *
45 | * @var object
46 | */
47 | public $option_manager = [];
48 |
49 | /**
50 | * Plugin_Admin_Notices Class
51 | *
52 | * @var object
53 | */
54 | public $admin_notices = [];
55 |
56 |
57 | /**
58 | * Setup Class
59 | *
60 | * @param array $post_object Cleaned Post Object.
61 | */
62 | public function __construct( $post_object = [] ) {
63 | if ( true === empty( $post_object ) || true === empty( $post_object['action'] ) ) {
64 | return;
65 | }
66 |
67 | $this->post_object = $post_object;
68 | $this->post_action = $post_object['action'];
69 | $this->option_manager = new OptionManager();
70 | $this->admin_notices = new PluginAdminNotices();
71 | }//end __construct()
72 |
73 |
74 | /**
75 | * Init Update Action
76 | */
77 | public function init() {
78 | if ( true === empty( $this->post_object ) ) {
79 | return;
80 | }
81 |
82 | /*
83 | * Fires as an admin screen or script is being initialized.
84 | * https://developer.wordpress.org/reference/hooks/admin_init/
85 | */
86 | add_action(
87 | 'admin_init',
88 | [
89 | $this,
90 | 'update',
91 | ]
92 | );
93 | }//end init()
94 |
95 |
96 | /**
97 | * Security Check & Update On Action
98 | */
99 | public function update() {
100 | $this->security_check();
101 |
102 | // Init Cleaner.
103 | if ( 'cleaner' === $this->post_action ) {
104 | $this->cleaner();
105 | }
106 | }//end update()
107 |
108 |
109 | /**
110 | * Init Cleaner
111 | */
112 | private function cleaner() {
113 | if ( true === empty( $this->post_object ) || true === empty( $this->admin_notices ) ) {
114 | return;
115 | }
116 |
117 | if ( true !== empty( $this->post_object['check-data'] ) ) {
118 | $this->checkdata();
119 | }
120 |
121 | if ( true !== empty( $this->post_object['clean-data'] ) ) {
122 | $this->cleandata();
123 | }
124 |
125 | if ( true !== empty( $this->post_object['check-physical'] ) ) {
126 | $this->checkphysical();
127 | }
128 |
129 | if ( true !== empty( $this->post_object['clean-physical'] ) ) {
130 | $this->cleanphysical();
131 | }
132 |
133 | if ( true !== empty( $this->post_object['check-rewrite'] ) ) {
134 | $this->checkrewrite();
135 | }
136 |
137 | if ( true !== empty( $this->post_object['add-rewrite'] ) ) {
138 | $this->addrewrite();
139 | }
140 | }//end cleaner()
141 |
142 |
143 | /**
144 | * Check For Old Plugin Data
145 | */
146 | private function checkdata() {
147 | $message = false;
148 |
149 | // Old Data Found, Set Marker.
150 | if ( get_option( 'pc_robotstxt' ) || get_option( 'kb_robotstxt' ) || get_option( 'cd_rdte_content' ) ) {
151 | $this->option_manager->update_option( [ 'checkdata' => 'error' ] );
152 | $message = true;
153 | } else {
154 | $this->option_manager->delete_setting( 'checkdata' );
155 | }
156 |
157 | if ( true === $message ) {
158 | $this->admin_notices->add_notice( 'success', 'checkdata_notice', 'network' );
159 | } else {
160 | $this->admin_notices->add_notice( 'error', 'checkdata_done', 'network' );
161 | }
162 | }
163 |
164 |
165 | /**
166 | * Remove Old Plugin Data
167 | */
168 | private function cleandata() {
169 | // Remove Options.
170 | delete_option( 'pc_robotstxt' );
171 | delete_option( 'kb_robotstxt' );
172 | delete_option( 'cd_rdte_content' );
173 |
174 | // Remove Filters.
175 | remove_filter( 'robots_txt', 'cd_rdte_filter_robots' );
176 | remove_filter( 'robots_txt', 'ljpl_filter_robots_txt' );
177 | remove_filter( 'robots_txt', 'robots_txt_filter' );
178 |
179 | // Run Check Again.
180 | $this->checkData();
181 | }
182 |
183 |
184 | /**
185 | * Check For Phsyical Robots.txt File
186 | */
187 | private function checkphysical() {
188 | $message = false;
189 |
190 | // Robots.txt File Found.
191 | if ( true === file_exists( get_home_path() . 'robots.txt' ) ) {
192 | $this->option_manager->update_option( [ 'checkphysical' => 'error' ] );
193 | $message = true;
194 | } else {
195 | $this->option_manager->delete_setting( 'checkphysical' );
196 | }
197 |
198 | if ( true === $message ) {
199 | $this->admin_notices->add_notice( 'success', 'checkphysical_notice', 'network' );
200 | } else {
201 | $this->admin_notices->add_notice( 'error', 'checkphysical_done', 'network' );
202 | }
203 | }
204 |
205 |
206 | /**
207 | * Remove Physical Robots.txt File
208 | */
209 | private function cleanphysical() {
210 | // Remove Robots.txt File.
211 | if ( true === file_exists( get_home_path() . 'robots.txt' ) && true === is_writable( get_home_path() . 'robots.txt' ) ) {
212 | unlink( realpath( get_home_path() . 'robots.txt' ) );
213 | }
214 |
215 | // Robots.txt File Found.
216 | if ( true === file_exists( get_home_path() . 'robots.txt' ) ) {
217 | $this->option_manager->delete_setting( 'checkphysical' );
218 | $this->admin_notices->add_notice( 'error', 'checkphysical_error', 'network' );
219 | } else {
220 | $this->checkphysical();
221 | }
222 | }
223 |
224 |
225 | /**
226 | * Check For Missing Rewrite Rules
227 | */
228 | private function checkrewrite() {
229 | $message = false;
230 |
231 | // Get Rewrite Rules.
232 | $rules = get_option( 'rewrite_rules' );
233 |
234 | // Flush Rules If Needed.
235 | if ( empty( $rules ) ) {
236 | flush_rewrite_rules();
237 | }
238 |
239 | // Error No Rewrite Rule Found, Set Marker.
240 | if ( true !== in_array( 'index.php?robots=1', (array) $rules, true ) ) {
241 | $this->option_manager->update_option( [ 'checkrewrite' => 'error' ] );
242 | $message = true;
243 | } else {
244 | $this->option_manager->delete_setting( 'checkrewrite' );
245 | }
246 |
247 | if ( true === $message ) {
248 | $this->admin_notices->add_notice( 'success', 'checkrewrite_notice', 'network' );
249 | } else {
250 | $this->admin_notices->add_notice( 'success', 'checkrewrite_done', 'network' );
251 | }
252 | }
253 |
254 |
255 | /**
256 | * Add Missing Rewrite Rule
257 | */
258 | private function addrewrite() {
259 | // Get Rewrite Rules.
260 | $rules = get_option( 'rewrite_rules' );
261 |
262 | // Add Missing Rule.
263 | if ( true !== in_array( 'index.php?robots=1', (array) $rules, true ) ) {
264 | // Set Proper Keys.
265 | $rule_key = 'robots\.txt$';
266 | $rules[ $rule_key ] = 'index.php?robots=1';
267 |
268 | // Update Rules.
269 | update_option( 'rewrite_rules', $rules );
270 |
271 | // Flush Rules.
272 | flush_rewrite_rules();
273 | }
274 |
275 | // Recheck Rewrite Rules.
276 | $this->checkRewrite();
277 | }
278 | }//end class
279 |
--------------------------------------------------------------------------------
/inc/classes/class-do-save-append-rules.php:
--------------------------------------------------------------------------------
1 |
8 | * @license GNU GPLv3
9 | * @link /LICENSE
10 | */
11 |
12 | namespace MsRobotstxtManager;
13 |
14 | if ( false === defined( 'ABSPATH' ) ) {
15 | exit;
16 | }
17 |
18 | use MsRobotstxtManager\Trait_Security_Check as TraitSecurityCheck;
19 | use MsRobotstxtManager\Plugin_Admin_Notices as PluginAdminNotices;
20 | use MsRobotstxtManager\Do_Build_Robotstxt as DoBuildRobotstxt;
21 | use MsRobotstxtManager\Option_Manager as OptionManager;
22 |
23 | /**
24 | * Update Website Append Rules
25 | */
26 | final class Do_Save_Append_Rules {
27 | use TraitSecurityCheck;
28 |
29 | /**
30 | * Plugin Admin Post Object.
31 | *
32 | * @var array
33 | */
34 | public $post_object = [];
35 |
36 | /**
37 | * Post Action To Take.
38 | *
39 | * @var string
40 | */
41 | public $post_action = [];
42 |
43 | /**
44 | * Option_Manager Class.
45 | *
46 | * @var object
47 | */
48 | public $option_manager = [];
49 |
50 | /**
51 | * Plugin_Admin_Notices Class
52 | *
53 | * @var object
54 | */
55 | public $admin_notices = [];
56 |
57 | /**
58 | * Do_Build_Robotstx Object.
59 | *
60 | * @var object
61 | */
62 | public $build_robotstxt = [];
63 |
64 |
65 | /**
66 | * Setup Class
67 | *
68 | * @param array $post_object Cleaned Post Object.
69 | */
70 | public function __construct( $post_object = [] ) {
71 | if ( true === empty( $post_object ) || true === empty( $post_object['action'] ) ) {
72 | return;
73 | }
74 |
75 | $this->post_object = $post_object;
76 | $this->post_action = $post_object['action'];
77 | $this->option_manager = new OptionManager();
78 | $this->admin_notices = new PluginAdminNotices();
79 | $this->build_robotstxt = new DoBuildRobotstxt( $this->option_manager );
80 | }//end __construct()
81 |
82 |
83 | /**
84 | * Init Update Action
85 | */
86 | public function init() {
87 | if ( true === empty( $this->post_object ) ) {
88 | return;
89 | }
90 |
91 | /*
92 | * Fires as an admin screen or script is being initialized.
93 | * https://developer.wordpress.org/reference/hooks/admin_init/
94 | */
95 | add_action(
96 | 'admin_init',
97 | [
98 | $this,
99 | 'update',
100 | ]
101 | );
102 | }//end init()
103 |
104 |
105 | /**
106 | * Security Check & Update On Action
107 | */
108 | public function update() {
109 | $this->security_check();
110 |
111 | // Website Append Rules.
112 | if ( 'append' === $this->post_action ) {
113 | $this->save_append_rules();
114 | }
115 | }//end update()
116 |
117 |
118 | /**
119 | * Website Append Rules
120 | */
121 | private function save_append_rules() {
122 | $message = false;
123 |
124 | if ( true !== empty( $this->post_object['append'] ) ) {
125 | $this->option_manager->update_setting( 'append', $this->post_object['append'] );
126 | $message = true;
127 | }
128 |
129 | if ( true === empty( $this->post_object['append'] ) ) {
130 | $this->option_manager->delete_setting( 'append' );
131 | $message = true;
132 | }
133 |
134 | if ( true !== empty( $this->post_object['override'] ) ) {
135 | $this->option_manager->update_setting( 'override', 1 );
136 | } else {
137 | $this->option_manager->delete_setting( 'override' );
138 | }
139 |
140 | // Remove Disable Marker.
141 | $this->option_manager->delete_setting( 'disable' );
142 |
143 | if ( true === $message ) {
144 | // Build Robots.txt Files.
145 | $this->build_robotstxt->init();
146 |
147 | $this->admin_notices->add_notice( 'success', 'append_success' );
148 | }
149 | }//end save_append_rules()
150 | }//end class
151 |
--------------------------------------------------------------------------------
/inc/classes/class-do-save-network-robotstxt.php:
--------------------------------------------------------------------------------
1 |
8 | * @license GNU GPLv3
9 | * @link /LICENSE
10 | */
11 |
12 | namespace MsRobotstxtManager;
13 |
14 | if ( false === defined( 'ABSPATH' ) ) {
15 | exit;
16 | }
17 |
18 | use MsRobotstxtManager\Trait_Security_Check as TraitSecurityCheck;
19 | use MsRobotstxtManager\Plugin_Admin_Notices as PluginAdminNotices;
20 | use MsRobotstxtManager\Option_Manager as OptionManager;
21 |
22 | /**
23 | * Save Network Robots.txt File.
24 | */
25 | final class Do_Save_Network_Robotstxt {
26 | use TraitSecurityCheck;
27 |
28 | /**
29 | * Plugin Admin Post Object.
30 | *
31 | * @var array
32 | */
33 | public $post_object = [];
34 |
35 | /**
36 | * Post Action To Take.
37 | *
38 | * @var string
39 | */
40 | public $post_action = [];
41 |
42 | /**
43 | * Option_Manager Class.
44 | *
45 | * @var object
46 | */
47 | public $option_manager = [];
48 |
49 | /**
50 | * Plugin_Admin_Notices Class
51 | *
52 | * @var object
53 | */
54 | public $admin_notices = [];
55 |
56 |
57 | /**
58 | * Setup Class
59 | *
60 | * @param array $post_object Cleaned Post Object.
61 | */
62 | public function __construct( $post_object = [] ) {
63 | if ( true === empty( $post_object ) || true === empty( $post_object['action'] ) ) {
64 | return;
65 | }
66 |
67 | $this->post_action = $post_object['action'];
68 | $this->post_object = $post_object;
69 | $this->option_manager = new OptionManager();
70 | $this->admin_notices = new PluginAdminNotices();
71 | }//end __construct()
72 |
73 |
74 | /**
75 | * Init Update Action
76 | */
77 | public function init() {
78 | if ( true === empty( $this->post_object ) ) {
79 | return;
80 | }
81 |
82 | /*
83 | * Fires as an admin screen or script is being initialized.
84 | * https://developer.wordpress.org/reference/hooks/admin_init/
85 | */
86 | add_action(
87 | 'admin_init',
88 | [
89 | $this,
90 | 'update',
91 | ]
92 | );
93 | }//end init()
94 |
95 |
96 | /**
97 | * Security Check & Update On Action
98 | */
99 | public function update() {
100 | $this->security_check();
101 |
102 | // Save Network Robots.txt File.
103 | if ( 'save' === $this->post_action ) {
104 | $this->save_network_robotstxt();
105 | }
106 | }//end update()
107 |
108 |
109 | /**
110 | * Save Network Robots.txt
111 | */
112 | private function save_network_robotstxt() {
113 | $message = false;
114 |
115 | if ( true !== empty( $this->post_object ) && true !== empty( $this->post_object['robotstxt'] ) ) {
116 | $this->option_manager->update_site_setting( 'robotstxt', $this->post_object['robotstxt'] );
117 | $message = true;
118 | }
119 |
120 | if ( true !== empty( $this->post_object ) && true === empty( $this->post_object['robotstxt'] ) ) {
121 | $this->option_manager->delete_site_option();
122 | $message = true;
123 | }
124 |
125 | if ( true === $message ) {
126 | $this->admin_notices->add_notice( 'success', 'save_success', 'network' );
127 | }
128 | }//end save_network_robotstxt()
129 | }//end class
130 |
--------------------------------------------------------------------------------
/inc/classes/class-do-save-preset-as-robotstxt.php:
--------------------------------------------------------------------------------
1 |
8 | * @license GNU GPLv3
9 | * @link /LICENSE
10 | */
11 |
12 | namespace MsRobotstxtManager;
13 |
14 | if ( false === defined( 'ABSPATH' ) ) {
15 | exit;
16 | }
17 |
18 | use MsRobotstxtManager\Trait_Security_Check as TraitSecurityCheck;
19 | use MsRobotstxtManager\Plugin_Admin_Notices as PluginAdminNotices;
20 | use MsRobotstxtManager\Option_Manager as OptionManager;
21 |
22 | /**
23 | * Save Network Robots.txt File With Preset.
24 | */
25 | final class Do_Save_Preset_As_Robotstxt {
26 | use TraitSecurityCheck;
27 |
28 | /**
29 | * Plugin Admin Post Object.
30 | *
31 | * @var array
32 | */
33 | public $post_object = [];
34 |
35 | /**
36 | * Post Action To Take.
37 | *
38 | * @var string
39 | */
40 | public $post_action = [];
41 |
42 | /**
43 | * Option_Manager Class.
44 | *
45 | * @var object
46 | */
47 | public $option_manager = [];
48 |
49 | /**
50 | * Plugin_Admin_Notices Class
51 | *
52 | * @var object
53 | */
54 | public $admin_notices = [];
55 |
56 |
57 | /**
58 | * Setup Class
59 | *
60 | * @param array $post_object Cleaned Post Object.
61 | */
62 | public function __construct( $post_object = [] ) {
63 | if ( true === empty( $post_object ) || true === empty( $post_object['action'] ) ) {
64 | return;
65 | }
66 |
67 | $this->post_object = $post_object;
68 | $this->post_action = $post_object['action'];
69 | $this->option_manager = new OptionManager();
70 | $this->admin_notices = new PluginAdminNotices();
71 | }//end __construct()
72 |
73 |
74 | /**
75 | * Init Update Action
76 | */
77 | public function init() {
78 | if ( true === empty( $this->post_object ) ) {
79 | return;
80 | }
81 |
82 | /*
83 | * Fires as an admin screen or script is being initialized.
84 | * https://developer.wordpress.org/reference/hooks/admin_init/
85 | */
86 | add_action(
87 | 'admin_init',
88 | [
89 | $this,
90 | 'update',
91 | ]
92 | );
93 | }//end init()
94 |
95 |
96 | /**
97 | * Security Check & Update On Action
98 | */
99 | public function update() {
100 | $this->security_check();
101 |
102 | // Save Preset Robots.txt as Network Robots.txt File.
103 | if ( 'presets' === $this->post_action ) {
104 | $this->save_preset_as_robotstxt();
105 | }
106 | }//end update()
107 |
108 |
109 | /**
110 | * Save Preset Robots.txt as Network Robots.txt
111 | */
112 | private function save_preset_as_robotstxt() {
113 | $message = false;
114 | $preset = '';
115 |
116 | if ( true !== empty( $this->post_object['preset'] ) ) {
117 | $preset = $this->post_object['preset'];
118 | }
119 |
120 | switch ( $preset ) {
121 | case 'default-robotstxt':
122 | $this->option_manager->update_site_setting( 'robotstxt', $this->default_robotstxt() );
123 | $message = true;
124 | break;
125 |
126 | case 'defaultalt-robotstxt':
127 | $this->option_manager->update_site_setting( 'robotstxt', $this->defaultalt_robotstxt() );
128 | $message = true;
129 | break;
130 |
131 | case 'wordpress-robotstxt':
132 | $this->option_manager->update_site_setting( 'robotstxt', $this->wordpress_robotstxt() );
133 | $message = true;
134 | break;
135 |
136 | case 'open-robotstxt':
137 | $this->option_manager->update_site_setting( 'robotstxt', $this->open_robotstxt() );
138 | $message = true;
139 | break;
140 |
141 | case 'blogger-robotstxt':
142 | $this->option_manager->update_site_setting( 'robotstxt', $this->blogger_robotstxt() );
143 | $message = true;
144 | break;
145 |
146 | case 'block-robotstxt':
147 | $this->option_manager->update_site_setting( 'robotstxt', $this->blocked_robotstxt() );
148 | $message = true;
149 | break;
150 |
151 | case 'google-robotstxt':
152 | $this->option_manager->update_site_setting( 'robotstxt', $this->google_robotstxt() );
153 | $message = true;
154 | break;
155 | }
156 |
157 | if ( true === $message ) {
158 | $this->admin_notices->add_notice( 'success', 'save_success', 'network' );
159 | }
160 | }//end save_preset_as_robotstxt()
161 |
162 |
163 | /**
164 | * Default Robots.txt File
165 | */
166 | private function default_robotstxt() {
167 | $txt = "# robots.txt\n";
168 | $txt .= "User-agent: *\n";
169 | $txt .= "Disallow: /feed\n";
170 | $txt .= "Disallow: /feed/\n";
171 | $txt .= "Disallow: /cgi-bin/\n";
172 | $txt .= "Disallow: /comment\n";
173 | $txt .= "Disallow: /comments\n";
174 | $txt .= "Disallow: /trackback\n";
175 | $txt .= "Disallow: /comment/\n";
176 | $txt .= "Disallow: /comments/\n";
177 | $txt .= "Disallow: /trackback/\n";
178 | $txt .= "Disallow: /wp-admin/\n";
179 | $txt .= "Disallow: /wp-content/\n";
180 | $txt .= "Disallow: /wp-includes/\n";
181 | $txt .= "Disallow: /wp-login.php\n";
182 | $txt .= "Allow: /wp-admin/admin-ajax.php\n";
183 | $txt .= '{APPEND_WEBSITE_ROBOTSTXT}';
184 |
185 | return $txt;
186 | }
187 |
188 |
189 | /**
190 | * Default-Alt Robots.txt File
191 | */
192 | private function defaultalt_robotstxt() {
193 | $txt = "# robots.txt\n";
194 | $txt .= "User-agent: *\n";
195 | $txt .= "Disallow: */feed\n";
196 | $txt .= "Disallow: */feed/\n";
197 | $txt .= "Disallow: */comment/\n";
198 | $txt .= "Disallow: */comments/\n";
199 | $txt .= "Disallow: */trackback/\n";
200 | $txt .= "Disallow: */comment\n";
201 | $txt .= "Disallow: */comments\n";
202 | $txt .= "Disallow: */trackback\n";
203 | $txt .= "Disallow: /feed\n";
204 | $txt .= "Disallow: /feed/\n";
205 | $txt .= "Disallow: /cgi-bin/\n";
206 | $txt .= "Disallow: /comment\n";
207 | $txt .= "Disallow: /comment/\n";
208 | $txt .= "Disallow: /comments\n";
209 | $txt .= "Disallow: /comments/\n";
210 | $txt .= "Disallow: /trackback\n";
211 | $txt .= "Disallow: /trackback/\n";
212 | $txt .= "Disallow: /wp-admin/\n";
213 | $txt .= "Disallow: /wp-content/\n";
214 | $txt .= "Disallow: /wp-includes/\n";
215 | $txt .= "Disallow: /wp-login.php\n";
216 | $txt .= "Allow: /wp-admin/admin-ajax.php\n";
217 | $txt .= '{APPEND_WEBSITE_ROBOTSTXT}';
218 |
219 | return $txt;
220 | }
221 |
222 |
223 | /**
224 | * WordPress Only Robots.txt File
225 | */
226 | private function wordpress_robotstxt() {
227 | $txt = "# robots.txt\n";
228 | $txt .= "User-agent: *\n";
229 | $txt .= "Disallow: /wp-admin/\n";
230 | $txt .= "Disallow: /wp-includes/\n";
231 | $txt .= "Allow: /wp-admin/admin-ajax.php\n";
232 | $txt .= '{APPEND_WEBSITE_ROBOTSTXT}';
233 |
234 | return $txt;
235 | }
236 |
237 |
238 | /**
239 | * Open Robots.txt File
240 | */
241 | private function open_robotstxt() {
242 | $txt = "# robots.txt\n";
243 | $txt .= "User-agent: *\n";
244 | $txt .= "Disallow:\n";
245 | $txt .= '{APPEND_WEBSITE_ROBOTSTXT}';
246 |
247 | return $txt;
248 | }
249 |
250 |
251 | /**
252 | * Blogger Robots.txt File
253 | */
254 | private function blogger_robotstxt() {
255 | $txt = "# robots.txt\n";
256 | $txt .= "User-agent: *\n";
257 | $txt .= "Disallow: *?\n";
258 | $txt .= "Disallow: *.inc$\n";
259 | $txt .= "Disallow: *.php$\n";
260 | $txt .= "Disallow: */feed\n";
261 | $txt .= "Disallow: */feed/\n";
262 | $txt .= "Disallow: */author\n";
263 | $txt .= "Disallow: */comment/\n";
264 | $txt .= "Disallow: */comments/\n";
265 | $txt .= "Disallow: */trackback/\n";
266 | $txt .= "Disallow: */comment\n";
267 | $txt .= "Disallow: */comments\n";
268 | $txt .= "Disallow: */trackback\n";
269 | $txt .= "Disallow: /wp-\n";
270 | $txt .= "Disallow: /wp-*\n";
271 | $txt .= "Disallow: /feed\n";
272 | $txt .= "Disallow: /feed/\n";
273 | $txt .= "Disallow: /author\n";
274 | $txt .= "Disallow: /cgi-bin/\n";
275 | $txt .= "Disallow: /wp-admin/\n";
276 | $txt .= "Disallow: /comment/\n";
277 | $txt .= "Disallow: /comments/\n";
278 | $txt .= "Disallow: /trackback/\n";
279 | $txt .= "Disallow: /comment\n";
280 | $txt .= "Disallow: /comments\n";
281 | $txt .= "Disallow: /trackback\n";
282 | $txt .= "Disallow: /wp-admin/\n";
283 | $txt .= "Disallow: /wp-content/\n";
284 | $txt .= "Disallow: /wp-includes/\n";
285 | $txt .= "Disallow: /wp-login.php\n";
286 | $txt .= "Disallow: /wp-content/cache/\n";
287 | $txt .= "Disallow: /wp-content/themes/\n";
288 | $txt .= "Disallow: /wp-content/plugins/\n";
289 | $txt .= "Allow: /wp-admin/admin-ajax.php\n";
290 | $txt .= '{APPEND_WEBSITE_ROBOTSTXT}';
291 |
292 | return $txt;
293 | }
294 |
295 |
296 | /**
297 | * Disallow Website Robots.txt File
298 | */
299 | private function blocked_robotstxt() {
300 | $txt = "# robots.txt\n";
301 | $txt .= "User-agent: *\n";
302 | $txt .= 'Disallow: /';
303 |
304 | return $txt;
305 | }
306 |
307 |
308 | /**
309 | * Google Friendly Robots.txt File
310 | */
311 | private function google_robotstxt() {
312 | $txt = "# robots.txt\n";
313 | $txt .= "User-agent: *\n";
314 | $txt .= "Disallow: /wp-\n";
315 | $txt .= "Disallow: /feed\n";
316 | $txt .= "Disallow: /feed/\n";
317 | $txt .= "Disallow: /author\n";
318 | $txt .= "Disallow: /cgi-bin/\n";
319 | $txt .= "Disallow: /wp-admin/\n";
320 | $txt .= "Disallow: /comment/\n";
321 | $txt .= "Disallow: /comments/\n";
322 | $txt .= "Disallow: /trackback/\n";
323 | $txt .= "Disallow: /comment\n";
324 | $txt .= "Disallow: /comments\n";
325 | $txt .= "Disallow: /trackback\n";
326 | $txt .= "Disallow: /wp-content/\n";
327 | $txt .= "Disallow: /wp-includes/\n";
328 | $txt .= "Disallow: /wp-login.php\n";
329 | $txt .= "Disallow: /wp-content/cache/\n";
330 | $txt .= "Disallow: /wp-content/themes/\n";
331 | $txt .= "Disallow: /wp-content/plugins/\n";
332 | $txt .= "Allow: /wp-content/uploads\n";
333 | $txt .= "Allow: /wp-content/uploads/\n";
334 | $txt .= "Allow: /wp-admin/admin-ajax.php\n";
335 | $txt .= '{APPEND_WEBSITE_ROBOTSTXT}';
336 | $txt .= "\n";
337 | $txt .= "# google bot\n";
338 | $txt .= "User-agent: Googlebot\n";
339 | $txt .= "Disallow: /wp-*\n";
340 | $txt .= "Disallow: *?\n";
341 | $txt .= "Disallow: *.inc$\n";
342 | $txt .= "Disallow: *.php$\n";
343 | $txt .= "Disallow: */feed\n";
344 | $txt .= "Disallow: */feed/\n";
345 | $txt .= "Disallow: */author\n";
346 | $txt .= "Disallow: */comment/\n";
347 | $txt .= "Disallow: */comments/\n";
348 | $txt .= "Disallow: */trackback/\n";
349 | $txt .= "Disallow: */comment\n";
350 | $txt .= "Disallow: */comments\n";
351 | $txt .= "Disallow: */trackback\n";
352 | $txt .= "\n";
353 | $txt .= "# google image bot\n";
354 | $txt .= "User-agent: Googlebot-Image\n";
355 | $txt .= "Allow: /*\n";
356 |
357 | return $txt;
358 | }
359 | }//end class
360 |
--------------------------------------------------------------------------------
/inc/classes/class-get-robotstxt-rules.php:
--------------------------------------------------------------------------------
1 |
8 | * @license GNU GPLv3
9 | * @link /LICENSE
10 | */
11 |
12 | namespace MsRobotstxtManager;
13 |
14 | if ( false === defined( 'ABSPATH' ) ) {
15 | exit;
16 | }
17 |
18 | /**
19 | * Build Robots.txt Rule Statements
20 | */
21 | final class Get_Robotstxt_Rules {
22 | /**
23 | * Get the Upload Path Rule
24 | *
25 | * @return string
26 | */
27 | public function get_uploadpath() {
28 | // Get Upload Dir For This Website.
29 | $upload_dir = wp_upload_dir( null, false, true );
30 |
31 | if ( true === empty( $upload_dir['basedir'] ) ) {
32 | return esc_html__( 'Upload Path Not Set', 'multisite-robotstxt-manager' );
33 | }
34 |
35 | // Split The Path.
36 | $contents = explode( 'uploads', $upload_dir['basedir'] );
37 |
38 | // Return The Path.
39 | return 'Allow: /wp-content/uploads' . end( $contents ) . '/';
40 | }
41 |
42 |
43 | /**
44 | * Get Theme Path Rule
45 | *
46 | * @return string
47 | */
48 | public function get_themepath() {
49 | // Build Path For Theme.
50 | $path_to_themes = get_stylesheet_directory();
51 | $theme_path = 'Allow: ' . strstr( $path_to_themes, '/wp-content/themes' ) . '/';
52 |
53 | return $theme_path;
54 | }
55 |
56 |
57 | /**
58 | * Get Website Sitemap URL Rule
59 | *
60 | * @return string
61 | */
62 | public function get_sitemapurl() {
63 | // Get Site URL.
64 | $sitemap_url_base = get_option( 'siteurl' ) ? get_option( 'siteurl' ) : MS_ROBOTSTXT_MANAGER_BASE_URL;
65 |
66 | if ( true === file_exists( $sitemap_url_base . '/sitemap.xml' ) ) {
67 | $root_xml_file_location = get_headers( $sitemap_url_base . '/sitemap.xml' );
68 | }
69 |
70 | if ( true === file_exists( $sitemap_url_base . '/sitemaps/sitemap.xml' ) ) {
71 | $alt_xml_file_location = get_headers( $sitemap_url_base . '/sitemaps/sitemap.xml' );
72 | }
73 |
74 | // Check if xml sitemap exists.
75 | if ( true === isset( $root_xml_file_location[0] ) && 'HTTP/1.1 200 OK' === $root_xml_file_location[0] ) {
76 | // http://domain.com/sitemap.xml.
77 | $url = $sitemap_url_base . '/sitemap.xml';
78 | } elseif ( true === isset( $alt_xml_file_location[0] ) && 'HTTP/1.1 200 OK' === $alt_xml_file_location[0] ) {
79 | // http://domain.com/sitemaps/sitemap.xml.
80 | $url = $sitemap_url_base . '/sitemaps/sitemap.xml';
81 | } else {
82 | $url = '';
83 | }
84 |
85 | // Return the url or empty if no sitemap.
86 | return ( ! empty( $url ) ) ? 'Sitemap: ' . $url : '';
87 | }
88 | }//end class
89 |
--------------------------------------------------------------------------------
/inc/classes/class-msrobotstxtmanager.php:
--------------------------------------------------------------------------------
1 |
8 | * @license GNU GPLv3
9 | * @link /LICENSE
10 | */
11 |
12 | namespace MsRobotstxtManager;
13 |
14 | if ( false === defined( 'ABSPATH' ) ) {
15 | exit;
16 | }
17 |
18 | /**
19 | * Plugin Core
20 | */
21 | final class MsRobotstxtManager {
22 | /**
23 | * Init Plugin
24 | */
25 | public static function init() {
26 | require_once MS_ROBOTSTXT_MANAGER_PLUGIN_DIR . '/inc/instantiate-public-classes.php';
27 | require_once MS_ROBOTSTXT_MANAGER_PLUGIN_DIR . '/inc/instantiate-admin-classes.php';
28 | require_once MS_ROBOTSTXT_MANAGER_PLUGIN_DIR . '/inc/instantiate-network-classes.php';
29 | }//end init()
30 | }//end class
31 |
--------------------------------------------------------------------------------
/inc/classes/class-option-manager.php:
--------------------------------------------------------------------------------
1 |
8 | * @license GNU GPLv3
9 | * @link /LICENSE
10 | */
11 |
12 | namespace MsRobotstxtManager;
13 |
14 | if ( false === defined( 'ABSPATH' ) ) {
15 | exit;
16 | }
17 |
18 | /**
19 | * WordPress Options Manager
20 | */
21 | class Option_Manager {
22 | /**
23 | * Get Option Data
24 | *
25 | * @param string $str Option Name.
26 | *
27 | * @return array
28 | */
29 | public function get_option( $str = '' ) {
30 | /*
31 | * Retrieves an option value based on an option name.
32 | * https://developer.wordpress.org/reference/functions/get_option/
33 | */
34 | $get_option = get_option( MS_ROBOTSTXT_MANAGER_PLUGIN_NAME . $str );
35 |
36 | if ( true !== empty( $get_option ) ) {
37 | return $get_option;
38 | }
39 |
40 | return '';
41 | }//end get_option()
42 |
43 |
44 | /**
45 | * Get Option Setting
46 | *
47 | * @param mixed $setting_name Name Of Option To Get.
48 | * @param string $str Option Name.
49 | *
50 | * @return string
51 | */
52 | public function get_setting( $setting_name, $str = '' ) {
53 | $get_option = $this->get_option( $str );
54 |
55 | if ( true === isset( $get_option[ $setting_name ] ) ) {
56 | return $get_option[ $setting_name ];
57 | }
58 |
59 | return '';
60 | }//end get_setting()
61 |
62 |
63 | /**
64 | * Get Network Site Option
65 | *
66 | * @param string $str Option Name.
67 | *
68 | * @return array
69 | */
70 | public function get_site_option( $str = '' ) {
71 | /*
72 | * Retrieve an option value for the current network based on name of option.
73 | * https://developer.wordpress.org/reference/functions/get_site_option/
74 | */
75 | $get_option = get_site_option( MS_ROBOTSTXT_MANAGER_PLUGIN_NAME . $str );
76 |
77 | if ( true !== empty( $get_option ) ) {
78 | return $get_option;
79 | }
80 |
81 | return '';
82 | }//end get_site_option()
83 |
84 |
85 | /**
86 | * Get Network Option Setting
87 | *
88 | * @param mixed $setting_name Name Of Option To Get.
89 | * @param string $str Option Name.
90 | *
91 | * @return string
92 | */
93 | public function get_site_setting( $setting_name, $str = '' ) {
94 | $get_option = $this->get_site_option( $str );
95 |
96 | if ( true === isset( $get_option[ $setting_name ] ) ) {
97 | return $get_option[ $setting_name ];
98 | }
99 |
100 | return '';
101 | }//end get_site_setting()
102 |
103 |
104 | /**
105 | * Update Option Array
106 | *
107 | * @param mixed $option_array Prepared Option Array.
108 | * @param string $str Option Name.
109 | */
110 | public function update_option( $option_array = [], $str = '' ) {
111 | if ( true === empty( $option_array ) ) {
112 | return;
113 | }
114 |
115 | /*
116 | * Update the value of an option that was already added.
117 | * https://developer.wordpress.org/reference/functions/update_option/
118 | */
119 | update_option(
120 | MS_ROBOTSTXT_MANAGER_PLUGIN_NAME . $str,
121 | $option_array
122 | );
123 | }//end update_option()
124 |
125 |
126 | /**
127 | * Update Option Array
128 | *
129 | * @param array $option_value Data To Save.
130 | * @param string $str Option Name.
131 | */
132 | public function update_site_option( $option_value = [], $str = '' ) {
133 | if ( true === empty( $option_value ) ) {
134 | return;
135 | }
136 |
137 | /*
138 | * Update the value of an option that was already added for the current network.
139 | * https://developer.wordpress.org/reference/functions/update_site_option/
140 | */
141 | update_site_option(
142 | MS_ROBOTSTXT_MANAGER_PLUGIN_NAME . $str,
143 | $option_value
144 | );
145 | }//end update_site_option()
146 |
147 |
148 | /**
149 | * Update Setting Within Option
150 | *
151 | * @param mixed $setting_name Name Of Option To Save.
152 | * @param mixed $setting_value The Value To Save.
153 | * @param string $str Option Name.
154 | */
155 | public function update_setting( $setting_name, $setting_value, $str = '' ) {
156 | $get_option = $this->get_option( $str );
157 |
158 | if ( true === empty( $get_option ) ) {
159 | $get_option = [];
160 | }
161 |
162 | if ( true === is_array( $get_option ) && true === array_key_exists( $setting_name, $get_option ) ) {
163 | unset( $get_option[ $setting_name ] );
164 | }
165 |
166 | $this->update_option( array_merge( $get_option, [ $setting_name => $setting_value ] ), $str );
167 | }//end update_setting()
168 |
169 |
170 | /**
171 | * Update Setting Within Network Option
172 | *
173 | * @param mixed $setting_name Name Of Option To Save.
174 | * @param mixed $setting_value The Value To Save.
175 | * @param string $str Option Name.
176 | */
177 | public function update_site_setting( $setting_name, $setting_value, $str = '' ) {
178 | $get_option = $this->get_site_option( $str );
179 |
180 | if ( true === empty( $get_option ) ) {
181 | $get_option = [];
182 | }
183 |
184 | if ( true === is_array( $get_option ) && true === array_key_exists( $setting_name, $get_option ) ) {
185 | unset( $get_option[ $setting_name ] );
186 | }
187 |
188 | $this->update_site_option( array_merge( $get_option, [ $setting_name => $setting_value ] ), $str );
189 | }//end update_site_setting()
190 |
191 |
192 | /**
193 | * Delete Option
194 | *
195 | * @param string $str Option Name.
196 | *
197 | * @return void
198 | */
199 | public function delete_option( $str = '' ) {
200 | $get_option = $this->get_option( $str );
201 |
202 | if ( true === isset( $get_option ) ) {
203 | /*
204 | * Removes a option by name.
205 | * https://developer.wordpress.org/reference/functions/delete_option/
206 | */
207 | delete_option( MS_ROBOTSTXT_MANAGER_PLUGIN_NAME . $str );
208 | }
209 | }//end delete_option()
210 |
211 |
212 | /**
213 | * Delete Network Site Option
214 | *
215 | * @param string $str Option Name.
216 | *
217 | * @return void
218 | */
219 | public function delete_site_option( $str = '' ) {
220 | $get_option = $this->get_site_option( $str );
221 |
222 | if ( true === isset( $get_option ) ) {
223 | /*
224 | * Removes a option by name for the current network.
225 | * https://developer.wordpress.org/reference/functions/delete_site_option/
226 | */
227 | delete_site_option( MS_ROBOTSTXT_MANAGER_PLUGIN_NAME . $str );
228 | }
229 | }//end delete_site_option()
230 |
231 |
232 | /**
233 | * Delete Option Setting
234 | *
235 | * @param mixed $setting_name Name Of Option To Delete.
236 | * @param string $str Option Name.
237 | *
238 | * @return void
239 | */
240 | public function delete_setting( $setting_name = '', $str = '' ) {
241 | if ( true === empty( $setting_name ) ) {
242 | return;
243 | }
244 |
245 | $get_option = $this->get_option( $str );
246 |
247 | if ( true === is_array( $get_option ) && true === array_key_exists( $setting_name, $get_option ) ) {
248 | unset( $get_option[ $setting_name ] );
249 |
250 | if ( true !== empty( $get_option ) ) {
251 | /*
252 | * Update the value of an option that was already added.
253 | * https://developer.wordpress.org/reference/functions/update_option/
254 | */
255 | update_option(
256 | MS_ROBOTSTXT_MANAGER_PLUGIN_NAME . $str,
257 | $get_option
258 | );
259 | }
260 | }
261 |
262 | if ( true === empty( $get_option ) ) {
263 | $this->delete_option( $str );
264 | }
265 | }//end delete_setting()
266 | }//end class
267 |
--------------------------------------------------------------------------------
/inc/classes/class-plugin-activate.php:
--------------------------------------------------------------------------------
1 |
8 | * @license GNU GPLv3
9 | * @link /LICENSE
10 | */
11 |
12 | namespace MsRobotstxtManager;
13 |
14 | if ( false === defined( 'ABSPATH' ) ) {
15 | exit;
16 | }
17 |
18 | /**
19 | * Activation Rules
20 | */
21 | final class Plugin_Activate {
22 |
23 | /**
24 | * Init Plugin Activation
25 | */
26 | public static function init() {
27 | /*
28 | * Retrieves the current WordPress version
29 | * https://developer.wordpress.org/reference/functions/get_bloginfo/
30 | */
31 | $wp_version = get_bloginfo( 'version' );
32 |
33 | if ( true === version_compare( $wp_version, 3.8, '<' ) ) {
34 | /*
35 | * Kill WordPress execution and display HTML message with error message.
36 | * https://developer.wordpress.org/reference/functions/wp_die/
37 | *
38 | * Escaping for HTML blocks.
39 | * https://developer.wordpress.org/reference/functions/esc_html/
40 | */
41 | wp_die( esc_html__( 'WordPress 3.8 is required. Please upgrade WordPress and try again.', 'multisite-robotstxt-manager' ) );
42 | }
43 |
44 | // Maybe Save Robots.txt As Plugin Robots.txt.
45 | self::set_robotstxt();
46 | }//end init()
47 |
48 |
49 | /**
50 | * Maybe Set Plugin Robots.txt
51 | */
52 | public static function set_robotstxt() {
53 | /*
54 | * Retrieve an option value for the current network based on name of option.
55 | * https://developer.wordpress.org/reference/functions/get_site_option/
56 | */
57 | $plugin_option = get_site_option( MS_ROBOTSTXT_MANAGER_PLUGIN_NAME );
58 |
59 | // Set Plugin Robots.txt From Website Robots.txt.
60 | if ( true === empty( $plugin_option ) && true !== empty( self::get_website_robotstxt() ) ) {
61 | /*
62 | * Update the value of an option that was already added for the current network.
63 | * https://developer.wordpress.org/reference/functions/update_site_option/
64 | */
65 | update_site_option( MS_ROBOTSTXT_MANAGER_PLUGIN_NAME, self::get_website_robotstxt() );
66 | }
67 |
68 | // Set Plugin Robots.txt Based On Default WordPress robots.txt - Unable To Read Robots.txt.
69 | if ( true === empty( $plugin_option ) && true === empty( self::get_website_robotstxt() ) ) {
70 | $preset_robotstxt['robotstxt'] = "User-agent: *\n";
71 | $preset_robotstxt['robotstxt'] .= "Disallow: /wp-admin/\n";
72 | $preset_robotstxt['robotstxt'] .= "Allow: /wp-admin/admin-ajax.php\n";
73 | $preset_robotstxt['robotstxt'] .= '{APPEND_WEBSITE_ROBOTSTXT}';
74 |
75 | /*
76 | * Update the value of an option that was already added for the current network.
77 | * https://developer.wordpress.org/reference/functions/update_site_option/
78 | */
79 | update_site_option( MS_ROBOTSTXT_MANAGER_PLUGIN_NAME, $preset_robotstxt );
80 | }
81 | }//end set_robotstxt()
82 |
83 |
84 | /**
85 | * Get Local Website Robots.txt File Body
86 | */
87 | public static function get_website_robotstxt() {
88 | $robotstxt = '';
89 |
90 | /*
91 | * Retrieve the raw response from the HTTP request using the GET method.
92 | * https://developer.wordpress.org/reference/functions/wp_remote_get/
93 | */
94 | $website_robotstxt = wp_remote_get( get_home_url() . '/robots.txt' );
95 |
96 | /*
97 | * Check whether variable is a WordPress Error.
98 | * https://developer.wordpress.org/reference/functions/is_wp_error/
99 | *
100 | * Issue: https://github.com/ChrisWinters/multisite-robotstxt-manager/issues/8
101 | */
102 | if ( true === is_wp_error( $website_robotstxt ) ) {
103 | return $robotstxt;
104 | }
105 |
106 | if ( true !== empty( $website_robotstxt['response']['code'] ) && '200' === $website_robotstxt['response']['code'] && true !== empty( $website_robotstxt['body'] ) ) {
107 | $robotstxt = $website_robotstxt['body'] . "\n";
108 | $robotstxt .= '{APPEND_WEBSITE_ROBOTSTXT}';
109 | }
110 |
111 | return $robotstxt;
112 | }//end get_website_robotstxt()
113 | }//end class
114 |
--------------------------------------------------------------------------------
/inc/classes/class-plugin-admin-notices.php:
--------------------------------------------------------------------------------
1 |
8 | * @license GNU GPLv3
9 | * @link /LICENSE
10 | */
11 |
12 | namespace MsRobotstxtManager;
13 |
14 | if ( false === defined( 'ABSPATH' ) ) {
15 | exit;
16 | }
17 |
18 | /**
19 | * Plugin Admin Area Notices
20 | */
21 | final class Plugin_Admin_Notices {
22 | /**
23 | * Notice Messages.
24 | *
25 | * @var array
26 | */
27 | public $message = [];
28 |
29 |
30 | /**
31 | * Set Class Params
32 | *
33 | * @return void
34 | */
35 | public function __construct() {
36 | $this->notice = '';
37 | }//end __construct()
38 |
39 |
40 | /**
41 | * Return Message Based On Key.
42 | *
43 | * @param string $message Message Key To Return.
44 | */
45 | private function messages( $message = '' ) {
46 | $messages = [
47 | 'update_success' => __(
48 | 'Rules Updated.',
49 | 'includes'
50 | ),
51 | 'robotstxt_success' => __(
52 | 'Robots.txt File Generated.',
53 | 'includes'
54 | ),
55 | 'network_updated' => __(
56 | 'Network Websites Updated.',
57 | 'includes'
58 | ),
59 | 'member_updated' => __(
60 | 'Network Member Websites Updated.',
61 | 'includes'
62 | ),
63 | 'update_error' => __(
64 | 'Settings Update Failed.',
65 | 'includes'
66 | ),
67 | 'save_success' => __(
68 | 'Network Robots.txt File Saved.',
69 | 'includes'
70 | ),
71 | 'append_success' => __(
72 | 'Append Rules Saved.',
73 | 'includes'
74 | ),
75 | 'input_error' => __(
76 | 'A Selection Is Required.',
77 | 'includes'
78 | ),
79 | 'delete_success' => __(
80 | 'All Plugin Settings Deleted.',
81 | 'includes'
82 | ),
83 | 'checkdata_notice' => __(
84 | 'Old robots.txt file data found! Click the "remove old data" button to remove the old data.',
85 | 'includes'
86 | ),
87 | 'checkdata_done' => __(
88 | 'No old robots.txt file data found.',
89 | 'includes'
90 | ),
91 | 'checkphysical_notice' => __(
92 | 'A real robots.txt file was found within the websites root directory. Click the "delete physical file" to delete the robots.txt file.',
93 | 'includes'
94 | ),
95 | 'checkphysical_done' => __(
96 | 'A physical robots.txt file was not found.',
97 | 'includes'
98 | ),
99 | 'checkphysical_error' => __(
100 | 'The plugin was unable to delete the robots.txt file due to file permissions. Manual deletion required.',
101 | 'includes'
102 | ),
103 | 'checkrewrite_notice' => __(
104 | 'This website is missing the robots.txt Rewrite Rule. Click the "correct missing rules" button to add the missing rule.',
105 | 'includes'
106 | ),
107 | 'checkrewrite_done' => __(
108 | 'Proper Rewrite Rule found.',
109 | 'includes'
110 | ),
111 | 'disable_success' => __(
112 | 'Default WordPress robots.txt file restored.',
113 | 'includes'
114 | ),
115 | 'upgraded_already' => __(
116 | 'Plugin has already been upgraded.',
117 | 'includes'
118 | ),
119 | 'upgrade_success' => __(
120 | 'Plugin upgraded. Please check the saved rules to ensure everything is correct.',
121 | 'includes'
122 | ),
123 | ];
124 |
125 | if ( true !== empty( $messages[ $message ] ) ) {
126 | return $messages[ $message ];
127 | }
128 | }//end messages()
129 |
130 |
131 | /**
132 | * Display Admin Notice
133 | *
134 | * @param string $type Message Type (success|error).
135 | * @param string $message Message Key To Get.
136 | * @param string $network Set to network to use network_admin_notices.
137 | */
138 | public function add_notice( $type = '', $message = '', $network = '' ) {
139 | if ( false === method_exists( $this, $type ) ) {
140 | return;
141 | }
142 |
143 | if ( true === empty( $message ) ) {
144 | return;
145 | }
146 |
147 | if ( true === empty( $this->messages( $message ) ) ) {
148 | return;
149 | }
150 |
151 | $admin_notice_type = 'admin_notices';
152 |
153 | if ( true !== empty( $network ) && 'network' === $network ) {
154 | $admin_notice_type = 'network_admin_notices';
155 | }
156 |
157 | // Set Notice Message.
158 | $this->notice = $this->messages( $message );
159 |
160 | /*
161 | * Prints admin screen notices.
162 | * https://developer.wordpress.org/reference/hooks/admin_notices/
163 | */
164 | add_action(
165 | $admin_notice_type,
166 | [
167 | $this,
168 | $type,
169 | ]
170 | );
171 | }//end add_notice()
172 |
173 |
174 | /**
175 | * Success Message HTML
176 | */
177 | public function success() {
178 | if ( true === empty( $this->notice ) ) {
179 | return;
180 | }
181 |
182 | /*
183 | * Sanitizes content for allowed HTML tags for post content.
184 | * https://developer.wordpress.org/reference/functions/wp_kses_post/
185 | */
186 | echo wp_kses_post( '
' . $this->notice . '
' );
187 | }//end success()
188 |
189 |
190 | /**
191 | * Error Message HTML
192 | */
193 | public function error() {
194 | if ( true === empty( $this->notice ) ) {
195 | return;
196 | }
197 |
198 | /*
199 | * Sanitizes content for allowed HTML tags for post content.
200 | * https://developer.wordpress.org/reference/functions/wp_kses_post/
201 | */
202 | echo wp_kses_post( '