update
339
wp-content/plugins/password-protect-page/LICENSE.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
601
wp-content/plugins/password-protect-page/README.txt
Normal file
@@ -0,0 +1,601 @@
|
||||
=== PPWP - Password Protect Pages ===
|
||||
Contributors: gaupoit, rexhoang, ppwp, buildwps, yuryonfolio
|
||||
Tags: password protect, password, restrict content, sitewide, password protection
|
||||
Requires at least: 4.7
|
||||
Requires PHP: 5.6
|
||||
Tested up to: 6.4.3
|
||||
Stable tag: 1.9.0
|
||||
License: GPLv2 or later
|
||||
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
Password protect WordPress pages and posts by user roles or with multiple passwords; protect your entire website with a single password.
|
||||
|
||||
== Description ==
|
||||
|
||||
Password Protect WordPress (PPWP) plugin offers a powerful and **all-in-one solution** to secure your website with passwords.
|
||||
|
||||
Whether you want to password protect WordPress categories, WooCommerce products, a few posts, or your entire website, PPWP plugin will help you do so with ease.
|
||||
|
||||
This plugin does not protect images or uploaded files so if you attach the media files to the protected pages or posts, they are still accessible to anyone with the link. Use [Prevent Direct Access (PDA) Gold](https://preventdirectaccess.com/features/?utm_source=wp.org&utm_medium=pda-gold-link&utm_campaign=ppwp-free) to block their direct file URL access.
|
||||
|
||||
Please note that the passwords will be stored in the post meta and this plugin will set a cookie to allow access to the protected pages or posts.
|
||||
|
||||
= An Inside Look at Password Protect WordPress - PPWP Pro =
|
||||
https://www.youtube.com/watch?v=myYsKXZyNwc
|
||||
|
||||
= Password Protected Features =
|
||||
The Lite version of Password Protect WordPress (PPWP) plugin offers the following features:
|
||||
|
||||
== Protect WordPress Pages & Posts with Unlimited Passwords ==
|
||||
The plugin extends WordPress built-in password protection feature and allows you to set multiple passwords per Page and Post. What's more, you can protect the content with just a single click. Once protected, a random password will be automatically generated for you.
|
||||
|
||||
= Password Protect WordPress Pages & Posts by User Roles =
|
||||
There is an option allowing you to password protect your WordPress Pages & Posts by user roles. In other words, you can set different passwords for different user roles, e.g. one for subscribers and one for editors.
|
||||
|
||||
= Prevent Password Abuse with reCAPTCHA =
|
||||
Stop password abuse and spam by bots and automated software with Google reCAPTCHA v2 or v3. Real users will be able to access protected content with ease as usual.
|
||||
|
||||
= Unlock Password Protected Content without Page Refresh =
|
||||
[Use Ajax to display protected content](https://passwordprotectwp.com/docs/unlock-password-protected-content-without-page-refresh/??utm_source=wp.org&utm_medium=ajax-link&utm_campaign=ppwp-free) without having to reload the entire page. It will help improve user experience and avoid server caching after users enter their password.
|
||||
|
||||
== Password Protect WordPress Categories ==
|
||||
Instead of creating an individual password for each post, you can protect all posts under one or multiple categories at once. Once users unlock a post successfully, they will be able to access the rest of the content automatically.
|
||||
|
||||
== Password Protect Entire WordPress Site ==
|
||||
You can [password protect the whole WordPress site](https://passwordprotectwp.com/features/password-protect-entire-wordpress-site/?utm_source=wp.org&utm_medium=sitewide-link&utm_campaign=ppwp-free) with a single password. All your website content including pages, posts, and other custom post types (but not media files) are locked as well.
|
||||
|
||||
== Partial Content Protection ==
|
||||
Partial Content Protection feature allows you to [password protect certain sections](https://passwordprotectwp.com/features/password-protect-partial-content/?utm_source=wp.org&utm_medium=free-pcp-link&utm_campaign=ppwp-free) of a page or post instead of hiding the entire content under a password form. This is useful when you want to create a teaser of premium content that encourages visitors to register/sign up to unlock the entire post.
|
||||
|
||||
= Section Protection =
|
||||
Section Protection takes PCP to the next level. The feature enables you to add [password-protected sections](https://passwordprotectwp.com/docs/section-protection/?utm_source=wp.org&utm_medium=section-protection-link&utm_campaign=ppwp-free) even on custom post types & templates created by top page builders such as Elementor and Divi.
|
||||
|
||||
= Show/Hide Premium Content at a Specific Time =
|
||||
|
||||
You can also choose when to publish the secure content to users. For example, they’re allowed to see the content without having to enter passwords from XXX to XXX using the following shortcode attributes.
|
||||
|
||||
`
|
||||
[ppwp passwords=123 on="2020/10/20 14:00:00" off="2020/10/30 14:00:00"] Your protected section will be shown automatically from 2 pm October 20, 2020 to 2 pm October 30, 2020[/ppwp]
|
||||
`
|
||||
|
||||
== Integrate with Page Builders ==
|
||||
Instead of using our shortcode to protect part of content, you can use our built-in module for the top page builders including:
|
||||
|
||||
* Elementor
|
||||
* Beaver Builder
|
||||
* WPBakery Page Builder*
|
||||
* Divi Builder*
|
||||
|
||||
*Supported; built-in UI block to be released soon.
|
||||
|
||||
These built-in modules allow you to set passwords, whitelisted roles, customize password forms, and so on via our friendly User Interface. You no longer have to deal with the complex shortcode attributes.
|
||||
|
||||
What's more, with PPWP Pro, you can even [protect the entire Elementor's templates](https://passwordprotectwp.com/docs/password-protect-partial-content-elementor/?utm_source=wp.org&utm_medium=pro-elementor-guide-link&utm_campaign=ppwp-free), Beaver Builder's rows, columns, and page templates as well as limiting and tracking password usage.
|
||||
|
||||
== Master Passwords ==
|
||||
When there are many password protected posts on your website, it becomes difficult and time-consuming to create or manage passwords for each content. That’s when master passwords come in handy.
|
||||
|
||||
Users will be able to [unlock all protected posts at once](https://passwordprotectwp.com/docs/master-passwords-unlock-all-protected-content/?utm_source=wp.org&utm_medium=master-pwd-link&utm_campaign=ppwp-free) with just one master password.
|
||||
|
||||
Please note that this feature **does not** password protect all posts automatically. It simply allows you to use master passwords to unlock those that you’ve already password protected. Original passwords attached to each post will still be working, together with these master passwords.
|
||||
|
||||
The master passwords feature also comes with an easy-to-use interface allowing you to create unlimited master passwords simultaneously and manage all of them in one place. You will have full control to (de)activate, delete passwords as well as restrict usage passwords by usage, time, and user role.
|
||||
|
||||
== Customize Password Form & Messages with WordPress Customizer ==
|
||||
Customize all your password forms, i.e. the sitewide login form, single and partial content protection (PCP) password form, via WordPress Customizer.
|
||||
|
||||
You’re allowed to remove or change our default logo to your own in the sitewide login form. You can also change the color, background and design of the form to match your theme’s color scheme.
|
||||
|
||||
[Besides the default login page](https://passwordprotectwp.com/docs/customize-sitewide-login-page/?utm_source=wp.org&utm_medium=customize-sitewide-link&utm_campaign=ppwp-free), you can now select one from our pre-designed themes that suits your site best.
|
||||
|
||||
As for [single password form](https://passwordprotectwp.com/docs/customize-password-form-wordpress-customizer/?utm_source=wp.org&utm_medium=customize-pcp-link&utm_campaign=ppwp-free), you're able to change the WordPress default error message as well as password form instructions, namely headline, descriptions, password input placeholder, and button text.
|
||||
|
||||
The button and text's font-size, color, and background can also be customized through a friendly WYSIWYG HTML Editor.
|
||||
|
||||
|
||||
== Hide Password Protected Content ==
|
||||
By default, your password protected content will still show up on various pages such as home and category page once published.
|
||||
|
||||
This feature allows you to control the visibility of your protected post types in different views:
|
||||
|
||||
* Hide posts from Recent Posts widgets
|
||||
* Hide posts from Next & Previous link on the single post
|
||||
* Hide posts on search results
|
||||
* Hide posts from Yoast SEO Google XML Sitemaps, and RSS
|
||||
* Hide posts on Frontpage, Author, and Archive pages including tag and category page
|
||||
* Protected pages hidden from search results, home page & everywhere they're listed
|
||||
|
||||
Even though the posts are hidden, those who know the URL will still have access to the pages (but not the protected content).
|
||||
|
||||
= Show Password Protected Content in RSS Feeds =
|
||||
Even though you choose to show password protected content in RSS, a password form will display instead of its actual content by default. With PPWP plugin, you're able to show all protected content in RSS feeds. There is also an option to make your RSS feeds public even if your site is hidden.
|
||||
|
||||
= Show Password Protected Post Excerpts =
|
||||
Many WordPress themes hide the post excerpt and featured image of password protected content by default. Enable this option to show excerpts of your password protect posts.
|
||||
|
||||
= Password's Cookies Expiration =
|
||||
By default, users won't have to re-enter passwords to access a protected page or post until its cookies expire. You can change the default cookie expiration time on the plugin settings page to whatever suits your use case. Or else, choose session cookies which will be removed automatically whenever users close their browser. As a result, users have to re-enter password when opening the browser again.
|
||||
|
||||
|
||||
> #### Pro Version
|
||||
> Our [PPWP Pro version](https://passwordprotectwp.com/features/?utm_source=wp.org&utm_medium=ppwp-pro-link&utm_campaign=ppwp-free) offers many more advanced features:
|
||||
>
|
||||
>* Password protect all WordPress custom post types including WooCommerce Products
|
||||
>* Password protect custom fields and custom page templates
|
||||
>* Manage all passwords while editing content or via our friendly popup
|
||||
>* Create unlimited passwords per user role
|
||||
>* Create the same passwords for multiple user roles
|
||||
>* Bypass password protection with Quick Access Links
|
||||
>* Customize Quick Access Links
|
||||
>* Create wildcard passwords
|
||||
>* Unlock Partial Content Protection (PCP) with master passwords
|
||||
>* Automatically protect all sub pages with one password
|
||||
>* Create multiple passwords for each protected category
|
||||
>* Set the same password for multiple pages
|
||||
>* Create unlimited global passwords for partial content protection shortcode
|
||||
>* Redirect to specific URLs after entering site-wide protection passwords
|
||||
>* Unlock all content at once and unlock partial sitewide protection with [Group Password Protection extension](https://passwordprotectwp.com/extensions/group-protection/?utm_source=wp.org&utm_medium=group-ext-link&utm_campaign=ppwp-free)
|
||||
>* Give users access to password-protected content upon form submissions with [Forms Integration extension](https://passwordprotectwp.com/extensions/forms-integration/?utm_source=wp.org&utm_medium=forms-integrate-ext-link&utm_campaign=ppwp-free)
|
||||
>* Use reCAPTCHA or Contact Form 7 in place of the password form with [Passwordless Authentication extension](https://passwordprotectwp.com/extensions/passwordless-authentication/?utm_source=wp.org&utm_medium=pa-ext-link&utm_campaign=ppwp-free)
|
||||
>* Track password usage, i.e. the time they're logged in, IP address and browser used, with [Statistics extension](https://passwordprotectwp.com/extensions/password-statistics/?utm_source=wp.org&utm_medium=stats-ext-link&utm_campaign=ppwp-free)
|
||||
>* [Password protect WordPress categories](https://passwordprotectwp.com/extensions/access-levels/?utm_source=wp.org&utm_medium=al-ext-link&utm_campaign=ppwp-free) with different access levels
|
||||
>* Integrate with [Prevent Direct Access Gold](https://preventdirectaccess.com/features/?utm_source=wp.org&utm_medium=pda-gold-link&utm_campaign=ppwp-free) to password protect files embedded in content
|
||||
>* Sell password-protected content via WooCommerce with [WooCommerce Integration extension](https://passwordprotectwp.com/extensions/woocommerce-integration/?utm_source=wp.org&utm_medium=woo-integrate-ext-link&utm_campaign=ppwp-free).
|
||||
>* Protect the entire shop page, including individual products and category pages with the same passwords.
|
||||
>* Import and export passwords as well as requiring users to provide both password and username or email to unlock protected content with [Password Suite extension](https://passwordprotectwp.com/extensions/password-suite/?utm_source=wp.org&utm_medium=suite-ext-link&utm_campaign=ppwp-free).
|
||||
>* Restrict password usage based on WordPress users or IP addresses as well as setting password expiration time after first use with [Smart Restriction extension](https://passwordprotectwp.com/extensions/smart-restriction/?utm_source=wp.org&utm_medium=sr-ext-link&utm_campaign=ppwp-free).
|
||||
>* Password protect files outside Media Library
|
||||
>
|
||||
> Check out [Password Protect WordPress (PPWP) Pro](https://passwordprotectwp.com/pricing/?utm_source=wp.org&utm_medium=plugin-desc-link&utm_campaign=ppwp-free) now!
|
||||
|
||||
Get access to all extensions and priority support with any of our [PPWP Pro membership](https://passwordprotectwp.com/membership?utm_source=wp.org&utm_medium=pro-memberships-link&utm_campaign=ppwp-free) plans.
|
||||
|
||||
= Multilingual supported =
|
||||
Our plugin works out of the box with the top leading multilingual WordPress plugins such as WPML, Polylang, and Loco Translate. In other words, you can [translate the password forms](https://passwordprotectwp.com/docs/how-to-translate-password-protect-wordpress-plugin/?utm_source=wp.org&utm_medium=guide-translate-link&utm_campaign=ppwp-free), including its headline, description, error message as well as placeholder and button text into the different languages.
|
||||
|
||||
= Documentation and support =
|
||||
|
||||
* For documentation and tutorials go to our [Documentation](https://passwordprotectwp.com/docs/?utm_source=wp.org&utm_medium=ppwp-pro-link&utm_campaign=ppwp-free)
|
||||
* Check out [compatible hostings, themes, and plugins](https://passwordprotectwp.com/docs/compatible-wordpress-plugins/?utm_source=wp.org&utm_medium=utm_medium=pro-compatiable-link&utm_campaign=ppwp-free) with PPWP
|
||||
* Visit our [PPWP Pro landing pages](http://ppwp.pro/?utm_source=wp.org&utm_medium=pro-landing-link&utm_campaign=ppwp-free) for more examples
|
||||
* If you have any more questions or want to request new features, contact us through [this form](https://passwordprotectwp.com/contact/?utm_source=wp.org&utm_medium=faq-link&utm_campaign=ppwp-free) or drop us an email at [hello@preventdirectaccess.com](mailto:hello@preventdirectaccess.com)
|
||||
|
||||
Note that we have to **migrate your default WordPress passwords** to our systems for our protection to work properly.
|
||||
|
||||
You may want to restore all your previously created passwords before deactivating the plugin to avoid all protected pages and posts becoming public.
|
||||
|
||||
Please check out these guides on [how to password protect WordPress page](https://passwordprotectwp.com/docs/getting-started/?utm_source=wp.org&utm_medium=guide-link&utm_campaign=ppwp-free) the right way.
|
||||
|
||||
= Privacy Policy =
|
||||
PPWP is designed to fully respect and protect personal information of its users. It does not collect any user information without your consent.
|
||||
|
||||
We're using GetResponse to communicate with our users in case they would like to opt in and receive future updates from us.
|
||||
User's emails will be first sent to an external API on our secure server before getting managed by GetResponse.
|
||||
|
||||
Please see our complete [Privacy Policy](https://passwordprotectwp.com/privacy-policy/?utm_source=wp.org&utm_medium=privacy-policy-link&utm_campaign=ppwp-free) and [GetResponse's](https://www.getresponse.com/legal/privacy).
|
||||
|
||||
== Installation ==
|
||||
|
||||
There are 2 easy ways to install our plugin:
|
||||
|
||||
= 1.The standard way =
|
||||
* Go to menu Plugins > Add New from your WordPress admin dashboard
|
||||
* Search for "WordPress Password Protect Page - PPWP Plugin"
|
||||
* Click to install
|
||||
* Activate Password Protect WordPress Lite from your Plugins page
|
||||
* Go to the editor page and set a secure password to protect your content
|
||||
* Read the documentation to [get started](https://passwordprotectwp.com/docs/password-protect-wordpress-lite/)
|
||||
|
||||
= 2.The nerdy way =
|
||||
* Download the plugin (.zip file) on the right column of this page
|
||||
* In your WordPress Admin, go to menu Plugins > Add New
|
||||
* Select the tab "Upload"
|
||||
* Upload the .zip file you just downloaded
|
||||
* Activate Password Protect WordPress Lite from your Plugins page
|
||||
* Go to the editor page and set a secure password to protect your content
|
||||
* Read the documentation to [get started](https://passwordprotectwp.com/docs/password-protect-wordpress-lite/)
|
||||
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= Why do I get an error message after entering the correct password? =
|
||||
|
||||
Below are 4 common reasons why the issue happens:
|
||||
|
||||
* You're protecting content on an ACF or WordPress custom field
|
||||
* You're using a custom page template
|
||||
* You're using a conflicting theme and unsupported page builder plugin
|
||||
* You're using an unsupported caching method and/or plugin
|
||||
|
||||
Please follow this guide on how to quickly [troubleshoot these common issues](https://passwordprotectwp.com/docs/basic-troubleshooting/?utm_source=wp.org&utm_medium=troubleshoot-faq-link&utm_campaign=ppwp-free). Learn more about [why password protected page is not working](https://passwordprotectwp.com/docs/wordpress-password-protected-page-not-working/?utm_source=wp.org&utm_medium=troubleshoot-faq-link&utm_campaign=ppwp-free).
|
||||
|
||||
= Does the plugin password protect WooCommerce products? =
|
||||
|
||||
Yes, the Pro version helps [password protect any WordPress custom post types](https://passwordprotectwp.com/docs/password-protect-wordpress-custom-post-types/?utm_source=wp.org&utm_medium=woo-faq-link&utm_campaign=ppwp-free), including WooCommerce product pages.
|
||||
|
||||
= Will my password protected content show up in Google search results? =
|
||||
|
||||
The Free version doesn't [block search engines from finding and indexing your content](https://passwordprotectwp.com/docs/block-google-search-indexing/?utm_source=wp.org&utm_medium=google-index-faq-link&utm_campaign=ppwp-free). However, your content won’t appear on Google and other search engine results once password protected by the Pro version.
|
||||
|
||||
= Can I password protect parts of WordPress page content? =
|
||||
|
||||
Yes, you can [secure parts of your post and page content](https://passwordprotectwp.com/docs/password-protect-wordpress-content-sections/?utm_source=wp.org&utm_medium=pcp-protection-faq-link&utm_campaign=ppwp-free) with a password using our [ppwp] shortcode.
|
||||
|
||||
= Could I create and manage all shortcode passwords at one place? =
|
||||
|
||||
Yes, you will be able to generate passwords under our plugin's settings page and then add them to [ppwp] shortcode in order to protect your content sections with Pro version. All these passwords will be [tracked and controlled in one place](https://passwordprotectwp.com/docs/manage-shortcode-global-passwords/?utm_source=wp.org&utm_medium=manage-pwd-faq-link&utm_campaign=ppwp-free).
|
||||
|
||||
= Could users see which passwords they're typing?
|
||||
|
||||
Yes, you can add a "show password" button allowing users to see what they're typing. This button can be added either via [WordPress Customizer](https://passwordprotectwp.com/docs/customize-password-form-wordpress-customizer/#pwd-reveal-btn?utm_source=wp.org&utm_medium=customizer-faq-link&utm_campaign=ppwp-free) or [manual template modification](https://passwordprotectwp.com/docs/customize-password-protected-form/#show-hide-pwd/?utm_source=wp.org&utm_medium=customizer-faq-link&utm_campaign=ppwp-free).
|
||||
|
||||
= Could I password protect a parent and all its child pages at once? =
|
||||
|
||||
Yes, the Pro version enables you to [automatically password protect child pages](https://passwordprotectwp.com/docs/password-protect-sub-pages-and-categories/?utm_source=wp.org&utm_medium=parent-child-pages-faq-link&utm_campaign=ppwp-free) once the parent page is locked up.
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
1. Protect your private pages and posts with multiple passwords.
|
||||
|
||||
2. Click on "Protect" button link for a new random password to be generated automatically.
|
||||
|
||||
3. Protect your private pages and posts by user roles. You can create one password per role with our Free version but unlimited passwords with our Pro version.
|
||||
|
||||
4. Users don't need to re-enter password when accessing your private content until its cookies expire. Simply change the default value under our plugin's Settings page.
|
||||
|
||||
5. It's easy to password protect your whole site with our plugin. Users are required to enter a password when accessing any pages or posts including the homepage.
|
||||
|
||||
6. Select which categories you want to protect and set a password. All posts under these categories will be unlocked at the same time.
|
||||
|
||||
7. Wrap your private content section with our [ppwp] shortcode.
|
||||
|
||||
8. This is what your post will look like after it is published. Visitors have to enter "password1" or "password2" to access the protected content.
|
||||
|
||||
9. Type "Password Protection (PPWP)" in the search field to find our built-in element in Elementor.
|
||||
|
||||
10. Type "Password Protect WordPress (PPWP)" in the search field to find our built-in module in Beaver Builder.
|
||||
|
||||
11. These built-in modules allow you to set passwords and whitelisted roles.
|
||||
|
||||
12. Customize password forms via our friendly User Interface.
|
||||
|
||||
13. Create master passwords to unlock all protected content at once.
|
||||
|
||||
14. You have full control over password tracking and restriction, i.e. by time, usage or user roles.
|
||||
|
||||
15. Customize password form text and design with WordPress Customizer.
|
||||
|
||||
16. This is our default PPWP sitewide login form.
|
||||
|
||||
17. This is our default PPWP single password form.
|
||||
|
||||
18. Control the visibility of your password protected content.
|
||||
|
||||
19. Enable this option to show excerpts of password protected content.
|
||||
|
||||
20. Restore default WordPress passwords before deactivating our plugin.
|
||||
|
||||
== Upgrade Notice ==
|
||||
|
||||
N/A
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 1.9.0 =
|
||||
|
||||
* [Feature] Delete All Expired Passwords feature added
|
||||
* [BugFix] API Protection with Sidewide Protection
|
||||
|
||||
= 1.8.9 =
|
||||
|
||||
* [Improvement] Comprehensive code comment documentation has been added
|
||||
* [Improvement] Added text domains for strings in places where they were previously missing
|
||||
* [Improvement] Removed unnecessary commented-out code, ensuring a cleaner and more efficient codebase
|
||||
* [Improvement] The settings page sidebar has been revised to provide users with updated information and a helpful guide
|
||||
|
||||
= 1.8.8 =
|
||||
|
||||
* [Refactoring] Validate data to prevent potential security issues
|
||||
|
||||
= 1.8.7 =
|
||||
|
||||
* [Refactoring] Update SQL calls to avoid SQL injection vulnerabilities
|
||||
|
||||
= 1.8.6.2 =
|
||||
|
||||
* [BugFix] Remove broken scripts in integrated page builders
|
||||
|
||||
= 1.8.6.1 =
|
||||
|
||||
* [BugFix] Remove broken scripts in single password forms
|
||||
|
||||
= 1.8.6 =
|
||||
|
||||
* [Refactoring] Validate and escape shortcode attributes
|
||||
* [Refactoring] Secure input and output data
|
||||
|
||||
= 1.8.5 =
|
||||
|
||||
* [Improvement] Provide a code snippet to show PCP passwords by default
|
||||
* [Integration] Support reCAPTCHA for PCP forms
|
||||
* [Improvement] Provide a hook to handle Central Login Forms without page refresh
|
||||
* [Improvement] Support protecting multilingual categories
|
||||
|
||||
= 1.8.4 =
|
||||
|
||||
* [Improvement] Allow customizing error messages when entering wrong passwords for Section Protection
|
||||
|
||||
= 1.8.3 =
|
||||
|
||||
* [Improvement] Not allow spaces at the beginning and ending of category passwords
|
||||
* [Improvement] Provide hooks to add settings options to Advanced tab in Pro version.
|
||||
|
||||
= 1.8.2 =
|
||||
|
||||
* [Feature] Display countdown timer in sitewide password form
|
||||
* [Improvement] Provide an option to hide sitewide password form
|
||||
* [Improvement] Secure input data
|
||||
|
||||
= 1.8.1 =
|
||||
|
||||
* [Improvement] Update PPWP settings UI
|
||||
* [UI Improvement] Display correct sidebar on PPWP settings page when deactivating Pro version
|
||||
|
||||
= 1.8.0 =
|
||||
|
||||
* [Improvement] Allow customizing description below PCP password form
|
||||
* [Improvement] Provide a shortcode attribute to add description above PCP password form submit button
|
||||
* [Improvement] Provide a hook to add a custom checkbox to single password form
|
||||
* [Improvement] Remove “Use Custom Form Action” option under Settings > Advanced
|
||||
* [Improvement] Update WordPress Customizer UI
|
||||
* [BugFix] Add <code><html></code> tags to display sitewide password form
|
||||
|
||||
= 1.7.10 =
|
||||
|
||||
* [Improvement] Update GetResponse API to 3.0
|
||||
* [Improvement] Change the PCP password form headline from <code><h3></code> to the <code><div></code> tag
|
||||
* [Improvement] Update PPWP settings UI
|
||||
|
||||
= 1.7.9.1 =
|
||||
|
||||
* [BugFix] Function “Use Shortcode within Page Builder” is not compatible with Divi
|
||||
|
||||
= 1.7.9 =
|
||||
|
||||
* [Feature] Protect content sections
|
||||
* [BugFix] Couldn’t save changes when customizing password forms via WordPress Customizer
|
||||
* [Improvement] Remove option “Use Custom Form Action” in the Advanced tab
|
||||
|
||||
= 1.7.8 =
|
||||
|
||||
* [Feature] Support unlocking Partial Content Protection without a page refresh
|
||||
* [Improvement] Refactor password form structure to allow changing additional field positions on single password form
|
||||
* [Improvement] Improve settings UI & add “what’s news” section
|
||||
* [BugFix] Show wrong error message when creating master passwords
|
||||
* [BugFix] Couldn’t save changes on text editor under WordPress Customizer
|
||||
|
||||
= 1.7.7 =
|
||||
|
||||
* [Feature] Unlock PCP content with master passwords; PPWP Pro required.
|
||||
* [Improvement] Allow removing master password’s expiry date.
|
||||
|
||||
= 1.7.6 =
|
||||
|
||||
* [Feature] Customize PCP form with WordPress Customizer.
|
||||
* [Improvement] Add "Show password" checkbox to PCP form.
|
||||
* [Improvement] Add hooks to improve session cookies feature in the Pro version.
|
||||
* [BugFix] Always display “on” value for additional field checkboxes on PPWP Statistics
|
||||
|
||||
= 1.7.5 =
|
||||
|
||||
* [Feature] Modify user permission to access plugin’s settings page
|
||||
* [Improvement] Allow adding multiple master passwords at once
|
||||
* [BugFix] Fatal error on PHP 8.0
|
||||
|
||||
= 1.7.4 =
|
||||
|
||||
* [Feature] Support reCAPTCHA for sitewide protection
|
||||
* [Feature] Support session cookie for sitewide protection
|
||||
* [Improvement] Share hook to customize sitewide login form
|
||||
* [Improvement] Support AJAX to work with reCAPTCHA
|
||||
|
||||
= 1.7.3 =
|
||||
|
||||
* [Improvement] Allow setting the cookie expiration time in seconds
|
||||
* [Improvement] Allow editing Label & Error Message in Elementor Widget
|
||||
* [BugFix] Can't edit password form via WP Customizer in Firefox, Opera, Edge, Safari,...
|
||||
|
||||
= 1.7.2 =
|
||||
|
||||
* [Feature] Allow customizing description below the password form
|
||||
* [Feature] Integrate with reCAPTCHA v2
|
||||
|
||||
= 1.7.1 =
|
||||
|
||||
* [Feature] Bulk action to delete master passwords
|
||||
* [Improvement] Remove caching notification under plugin's settings page
|
||||
|
||||
= 1.7.0 =
|
||||
|
||||
* [Feature] Apply reCAPTCHA to single password form
|
||||
* [Feature] Provide some pre-designed sitewide login page templates
|
||||
* [Improvement] Integrate "No reload page" feature with top page builders
|
||||
* [BugFix] Conflict with StoreVilla theme
|
||||
* [BugFix] Master cookie is saved with wrong format
|
||||
* [BugFix] Cookie is saved successfully but content is still locked
|
||||
* [BugFix] Plugin settings inaccessible for Editor role
|
||||
|
||||
|
||||
= 1.6.0 =
|
||||
|
||||
* [Feature] Show/hide partial content at a specific time
|
||||
* [Feature] Unlock password protected content without reloading page
|
||||
* [Feature] Support session cookies
|
||||
* [BugFix] Password category doesn't work properly with content belonging multiple categories
|
||||
* [BugFix] Redirect to homepage after users enter password if there is no referrer URL
|
||||
* [BugFix] Shortcode attributes of Pro version don't work if "Use Shortcode within Page Builder" is enabled
|
||||
|
||||
|
||||
= 1.5.2 =
|
||||
|
||||
* [Improvement] Auto backup default WordPress passwords
|
||||
* [Improvement] Add ppwp shortcode attributes to edit password label and error message
|
||||
* [Improvement] Migrate passwords of all post status
|
||||
* [BugFix] Description of pcp form displays wrong when enable "Use Shortcode within Page Builder" option
|
||||
* [BugFix] Post excerpts don't display when enable "Use Custom Form Action" option
|
||||
* [BugFix] Conflict with Impreza theme when displaying pcp form
|
||||
* [BugFix] Post is not protected with the password role is 0
|
||||
* [BugFix] Fix PHP Notice: register_rest_route notice happened with WP 5.5
|
||||
|
||||
|
||||
= 1.5.1 =
|
||||
|
||||
* [HotFix] Remove category ID in cookie
|
||||
|
||||
= 1.5.0 =
|
||||
|
||||
* [Feature] Protect content with one click
|
||||
* [Feature] Protect categories with a single password
|
||||
* [Improvement] Share hook to customize sitewide login form header and footer
|
||||
* [BugFix] ppwp shortcode breaks page structures created by page builders
|
||||
* [BugFix] ppwp shortcode inserted into Group block doesn't work properly
|
||||
* [BugFix] ppwp shortcode doesn't work on IE 11
|
||||
* [BugFix] Get WP_Customize_Section fatal error when activating the plugin
|
||||
|
||||
= 1.4.5.1 =
|
||||
|
||||
* [Feature] Share hook to handle tabs in sitewide sub-menu
|
||||
* [Improvement] Improve individual password form customizer
|
||||
* [BugFix] Use space instead of in single password form
|
||||
* [Improvement] Share hook to support custom form before rendering the password form.
|
||||
|
||||
= 1.4.5 =
|
||||
|
||||
* [Feature] Add option which forces to show content
|
||||
* [Feature] Allow users customize sitewide protection
|
||||
* [Feature] Display error message for sitewide protection
|
||||
* [Feature] Improve password form and customizer function
|
||||
* [Improvement] Move sitewide tab in sub-menu
|
||||
* [Improvement] Page visibility function always run in frontend
|
||||
* [BugFix] Allow displaying content in RSS while in protection
|
||||
|
||||
= 1.4.4 =
|
||||
|
||||
* [BugFix] Only load asserts (js) when rendering the shortcode.
|
||||
* [Improvement] Fire hooks in shortcode content, password handling and redirection.
|
||||
|
||||
= 1.4.3.2 =
|
||||
|
||||
* [HotFix] Security issue when do not encode the callback query param's value
|
||||
|
||||
= 1.4.3.1 =
|
||||
|
||||
* [HotFix] Using ob_flush after ob_end_clean that throws warning message in password form
|
||||
|
||||
= 1.4.3 =
|
||||
|
||||
* [BugFix] Cannot redirect if Referrer policy is no-referrer
|
||||
* [BugFix] Whitelist role not working as example on settings
|
||||
* [BugFix] Conflict with PPP because of using template_redirect
|
||||
* [Improvement] Improve Customize individual page with WP Customizer
|
||||
* [Feature] Add troubleshooting checklist
|
||||
* [Feature] Customize password form description for each page
|
||||
|
||||
= 1.4.2 =
|
||||
|
||||
* Fix shortcode wrong error message for unregistered custom post types
|
||||
* Add "Show Post Excerpt" option
|
||||
* Fix caching issue with SG Optimizer plugin
|
||||
|
||||
= 1.4.1 =
|
||||
|
||||
* Allow translating password forms with WPML & other top multilingual plugins
|
||||
|
||||
= 1.4.0 =
|
||||
|
||||
* Add option to hide password protected content
|
||||
* Improve integrating with caching plugins feature
|
||||
|
||||
= 1.3.0 =
|
||||
|
||||
* Enable Free users to customize Password Form
|
||||
* Create global passwords for pages and posts
|
||||
* Add hook whether to show/hide the password form
|
||||
* Entire site feature changes site title
|
||||
* Shortcode - Integrate with Beaver Builder
|
||||
* Shortcode - Integrate with Page Builders
|
||||
|
||||
= 1.2.3.4 =
|
||||
|
||||
* Fix fatal error when WP version is under 4.7
|
||||
|
||||
= 1.2.3.3 =
|
||||
|
||||
* Fix warning with add_submenu_page function on WP version 5.3
|
||||
* Fix style to compatible with WP 5.3
|
||||
* Add hook after shortcode settings UI
|
||||
* Add the filters that can adapt the new attributes
|
||||
|
||||
= 1.2.3.2 =
|
||||
|
||||
* Using the post_class instead of body_class that helps part of content feature works well
|
||||
|
||||
= 1.2.3.1 =
|
||||
|
||||
* Change Whitelist Roles -> Whitelisted Roles
|
||||
* Write unit test for part of content and password core service classes
|
||||
* Apply unit test in building and development process
|
||||
* Handle password form WooCommerce product when removing "woocommerce_before_single_product"
|
||||
* Run automation test of Pro version in building and deployment process
|
||||
* Show error and UI displays wrong
|
||||
* Unprotected post becomes protected when activating PPWP Pro
|
||||
* Fix not update post in gutenberg when use ppw
|
||||
|
||||
= 1.2.3 =
|
||||
|
||||
* HotFix for debug mode flag
|
||||
|
||||
= 1.2.2 =
|
||||
|
||||
* HotFix for debug mode flag
|
||||
|
||||
= 1.2.1 =
|
||||
|
||||
* Optimize & Remove Unnecessary CSS & JS files
|
||||
* Fix issue with the_password_form
|
||||
* Show error message under password field
|
||||
* Add new feature part of the content password protection
|
||||
|
||||
= 1.2.0 =
|
||||
* Revamp the architecture design
|
||||
|
||||
= 1.1.2.2 =
|
||||
* Fatal error when activating Pro & Lite version
|
||||
* Show notification when enter wrong password
|
||||
|
||||
= 1.1.2.1 =
|
||||
* Password Protect Entire Site is enabled but the password field is empty
|
||||
* Password Protect Entire Site doesn't work if Cookies Expiration Time is more than 9999 days
|
||||
* WP logo is missing on sub pages
|
||||
* Can't submit after error notification display in Chrome
|
||||
* Auto login a protected page without entering a password
|
||||
* The page reloads after entering the correct password
|
||||
* Integrate with WP Fastest Cache
|
||||
* Integrate with W3 Total Cache
|
||||
* Integrate with WP Super Cache
|
||||
* Show notice not work with sites use caching
|
||||
* Update the text when visitors can't see the password field
|
||||
* Support users which have multiple roles
|
||||
|
||||
= 1.1.2 =
|
||||
* Separate the password protected by roles from the page's content update.
|
||||
* Set password for Admin, when log-in by Editor then not enter the password.
|
||||
* Resolve the data conflict between gold and free version
|
||||
|
||||
= 1.1.1 =
|
||||
* Add new features that users can set the post's visibility with multiple passwords.
|
||||
* Change cookies lifetime to 1 day.
|
||||
* Enhance the css for the metabox.
|
||||
|
||||
= 1.0.0 =
|
||||
* Add UI in the pages/posts that allow users to set a password for each user role.
|
||||
1509
wp-content/plugins/password-protect-page/admin/class-ppw-admin.php
Normal file
1
wp-content/plugins/password-protect-page/admin/css/dist/ppw-setting.css
vendored
Normal file
1
wp-content/plugins/password-protect-page/admin/css/dist/ppw-setting.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){}]);
|
||||
1
wp-content/plugins/password-protect-page/admin/css/lib/select2.min.css
vendored
Normal file
6
wp-content/plugins/password-protect-page/admin/css/lib/toastr.min.css
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
Hide feature set password default in WP
|
||||
*/
|
||||
.editor-post-visibility__dialog-fieldset .editor-post-visibility__choice:nth-child(4), #the-list .inline-edit-col-left .inline-edit-group.wp-clearfix .alignleft:not(.inline-edit-private), #visibility-radio-password, label[for=visibility-radio-password], #post-visibility-select br:nth-child(8), #post-visibility-select br:nth-child(10) {
|
||||
display: none;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/* PPWP Sidebar Css */
|
||||
|
||||
.ppwp_setting_page {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.ppwp_setting_page .ppwp_wrap_subscribe_form {
|
||||
margin-left: 3%;
|
||||
width: 27%;
|
||||
}
|
||||
|
||||
.ppwp_wrap_al img {
|
||||
width: 100%;
|
||||
border-radius: 0 0 10px 10px;
|
||||
}
|
||||
|
||||
.ppwp_wrap_al h3 {
|
||||
margin-bottom: 0.5rem;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
.ppwp_wrap_subscribe_form .ppwp_subscribe_hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ppwp_subscribe_form {
|
||||
background-color: white;
|
||||
padding: 0 20px 20px 20px;
|
||||
margin-bottom: 20px;
|
||||
border: 1px solid #CCC;
|
||||
border-radius: 0 0 10px 10px;
|
||||
}
|
||||
|
||||
.ppwp_subscribe_form .input_email {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ppwp_subscribe_form .ppwp_subscribe_error {
|
||||
color: red;
|
||||
margin-top: 3px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Dynamic Sideabr*/
|
||||
#ppwp_right_column_metaboxes .main_container {
|
||||
background-color: white;
|
||||
padding: 20px 20px 20px 20px;
|
||||
margin-bottom: 20px;
|
||||
border: 1px solid #CCC;
|
||||
border-radius: 0 0 10px 10px;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#d9dee0',GradientType=0 );
|
||||
}
|
||||
|
||||
#ppwp_right_column_metaboxes img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
#ppwp_right_column_metaboxes ul {
|
||||
list-style: inherit;
|
||||
margin-left: 15px;
|
||||
}
|
||||
|
||||
#ppwp_right_column_metaboxes ul > li > ul {
|
||||
list-style: inside;
|
||||
list-style-type: circle;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/* PPWP Row Action */
|
||||
|
||||
.ppw-badge-protection {
|
||||
padding: 0.1rem 0.4rem;
|
||||
color: white;
|
||||
display: inline-block;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.ppw-badge-protection i.dashicons {
|
||||
font-size: 14px;
|
||||
margin-left: -2px;
|
||||
line-height: 18px;
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.ppw_unprotected_color {
|
||||
background-color: #D6D6D6;
|
||||
}
|
||||
|
||||
.ppw_protected_color {
|
||||
background-color: #ff8935;
|
||||
}
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 68 KiB |
1
wp-content/plugins/password-protect-page/admin/index.php
Normal file
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
||||
@@ -0,0 +1,13 @@
|
||||
/* Deactivate PPWP Js*/
|
||||
|
||||
(function ($) {
|
||||
'use strict';
|
||||
$(function () {
|
||||
$('a[aria-label="Deactivate Password Protect WordPress Lite"]').click(function () {
|
||||
var message = 'Please restore all your previously created passwords before deactivating the plugin to avoid all protected pages and posts becoming public.\nAre you sure you want to deactivate our PPWP Lite version now?';
|
||||
if (!confirm(message)) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,94 @@
|
||||
/* PPWP Customizer Js */
|
||||
|
||||
(function ($, api) {
|
||||
var customizePrefix = '_customize-input-';
|
||||
var themePrefix = 'ppw_customize_presets_settings';
|
||||
var defaultShowLogo = null;
|
||||
var defaultData = {
|
||||
'default1': {
|
||||
'#customize-control-ppwp_pro_form_instructions_background_color_control input.wp-color-picker' : ''
|
||||
},
|
||||
'default2': {
|
||||
'#customize-control-ppwp_pro_form_instructions_background_color_control input.wp-color-picker' : ''
|
||||
},
|
||||
'default3': {
|
||||
'#customize-control-ppwp_pro_form_instructions_background_color_control input.wp-color-picker' : ''
|
||||
},
|
||||
};
|
||||
|
||||
// Editor control.
|
||||
$(document).ready(function($) {
|
||||
$('textarea.wp-editor-area').each(function () {
|
||||
const $this = $(this),
|
||||
id = $this.attr('id'),
|
||||
$input = $('input[data-customize-setting-link="' + id + '"]');
|
||||
|
||||
$this.css('visibility', 'visible').on('keyup', function () {
|
||||
$input.val($this.val()).trigger('change');
|
||||
});
|
||||
|
||||
if (tinyMCE.get(id)) {
|
||||
const editor = tinyMCE.get(id);
|
||||
editor.on('change', function (e) {
|
||||
editor.save();
|
||||
$input.val(editor.getContent()).trigger('change');
|
||||
});
|
||||
} else {
|
||||
tinyMCE.init({
|
||||
menubar: false,
|
||||
selector: '#' + id,
|
||||
setup: function (editor) {
|
||||
const $wraps = $this.closest('.wp-core-ui.wp-editor-wrap');
|
||||
if ($wraps.length > 0) {
|
||||
const $wrap = $wraps[0];
|
||||
$($wrap).addClass('tmce-active').removeClass('html-active');
|
||||
}
|
||||
|
||||
editor.on('change', function (e) {
|
||||
editor.save();
|
||||
$input.val(editor.getContent()).trigger('change');
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('.customize-control-ppw-presets input[type="radio"]').on('change', function () {
|
||||
var theme = $(this).val();
|
||||
Object.keys(defaultData).forEach(function(theme) {
|
||||
if ( $('#' + themePrefix + theme).is(':checked') ) {
|
||||
var themeData = defaultData[theme];
|
||||
Object.keys(themeData).forEach(function(themeKey){
|
||||
changeInput(themeKey, themeData[themeKey], 'change');
|
||||
});
|
||||
}
|
||||
});
|
||||
var checkbox_values = $(this)
|
||||
.parents('.customize-control')
|
||||
.find('input[type="radio"]:checked')
|
||||
.val();
|
||||
$(this)
|
||||
.parents('.customize-control')
|
||||
.find('input[type="hidden"]')
|
||||
.val(checkbox_values)
|
||||
.delay(500)
|
||||
.trigger('change');
|
||||
$logo = $('#toggle-ppwp_pro_logo_disable_control');
|
||||
if (defaultShowLogo !== null) {
|
||||
defaultShowLogo = $logo.is(':checked');
|
||||
}
|
||||
if ( 'default0' !== theme && $logo.length > 0) {
|
||||
$logo.prop('checked', true).trigger('input');
|
||||
} else {
|
||||
$logo.prop('checked', defaultShowLogo).trigger('input');
|
||||
}
|
||||
});
|
||||
|
||||
function changeInput( key, value, type = 'input' ) {
|
||||
$(key).val(value).delay(500).trigger(type);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
})(jQuery, wp.customize);
|
||||
243
wp-content/plugins/password-protect-page/admin/js/dist/pcp-metabox.js
vendored
Normal file
1
wp-content/plugins/password-protect-page/admin/js/dist/ppw-row-action.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(t){var e={};function o(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,o),r.l=!0,r.exports}o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)o.d(n,r,function(e){return t[e]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=0)}([function(t,e){window.ppwpRowAction=function(t){return{handleOnClickRowAction:function(e){const o=t(`#ppw-protect-post_${e}`);if(!o)return;const{plugin_name:n}=ppw_row_action_data,r=o.attr("data-ppw-status");if(void 0===r)return;const s=o.text();if("Unprotect"===s&&"0"===r&&!confirm("All passwords will be removed if you unprotect this page. Do you want to proceed?"))return!1;o.css("pointer-events","none"),o.attr("title"),o.text(s+"ing..."),function(e,o,n){!function(e,o){const{ajax_url:n,nonce:r}=ppw_row_action_data;t.ajax({url:n,type:"POST",data:e,timeout:5e3,headers:{"X-WP-Nonce":r},success:function(t){o(t,null)},error:function(t){o(null,t)}})}({postId:e,status:r,action:"ppw_update_post_status",nonce:ppw_row_action_data.nonce},n)}(e,0,function(r,a){if(o.css("pointer-events","auto"),a)return o.text(s),void(400===a.status?toastr.error(a.responseJSON.message,n):toastr.error("Oops! Something went wrong. Please reload the page and try again.",n));const{server_status:c,message:u}=r;!function(e,o,n){const r=`#ppw-badge-protection_${n}`;e.attr("data-ppw-status",o);const s={status:1,label:"Protect"},a={status:0,label:"Unprotect"};s.status===o?(e.text(s.label),function(e,o,n){t(o).removeClass("ppw_protected_color"),t(o).addClass("ppw_unprotected_color"),t(o).html('<i class="dashicons dashicons-unlock"></i> unprotected')}(0,r)):(e.text(a.label),function(e,o,n){t(o).removeClass("ppw_unprotected_color"),t(o).addClass("ppw_protected_color"),t(o).html('<i class="dashicons dashicons-lock"></i> protected')}(0,r))}(o,c,e),toastr.success(u,n)})}}}(jQuery)}]);
|
||||
3
wp-content/plugins/password-protect-page/admin/js/lib/select2.min.js
vendored
Normal file
7
wp-content/plugins/password-protect-page/admin/js/lib/toastr.min.js
vendored
Normal file
9
wp-content/plugins/password-protect-page/config.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Subscription API
|
||||
*/
|
||||
|
||||
return (object) array(
|
||||
'debug_mode' => false,
|
||||
'subscribe_api' => 'https://loks4vx5i7.execute-api.ap-southeast-1.amazonaws.com/prod/mail',
|
||||
);
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* Abstract Class PPWP Background Task Manager
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
abstract class PPW_Background_Task_Manager extends PPW_Module {
|
||||
|
||||
/**
|
||||
* @var Background_Task
|
||||
*/
|
||||
protected $task_runner;
|
||||
|
||||
abstract public function get_action();
|
||||
abstract public function get_plugin_name();
|
||||
abstract public function get_plugin_label();
|
||||
abstract public function get_task_runner_class();
|
||||
abstract public function get_query_limit();
|
||||
|
||||
abstract protected function start_run();
|
||||
|
||||
public function __construct() {
|
||||
if ( empty( $_GET[ $this->get_action() ] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'run' === $_GET[ $this->get_action() ] && check_admin_referer( $this->get_action() . 'run' ) ) {
|
||||
$this->start_run();
|
||||
}
|
||||
|
||||
if ( 'continue' === $_GET[ $this->get_action() ] && check_admin_referer( $this->get_action() . 'continue' ) ) {
|
||||
$this->continue_run();
|
||||
}
|
||||
|
||||
wp_safe_redirect(
|
||||
remove_query_arg(
|
||||
array(
|
||||
$this->get_action(),
|
||||
'_wpnonce',
|
||||
)
|
||||
)
|
||||
);
|
||||
die;
|
||||
}
|
||||
|
||||
public function on_runner_start() {
|
||||
// Implement logger here
|
||||
}
|
||||
|
||||
public function on_runner_complete( $did_tasks = false ) {
|
||||
// Implement logger here
|
||||
$this->add_flag( 'completed' );
|
||||
|
||||
}
|
||||
|
||||
public function get_task_runner() {
|
||||
if ( empty( $this->task_runner ) ) {
|
||||
$class_name = $this->get_task_runner_class();
|
||||
$this->task_runner = new $class_name( $this );
|
||||
}
|
||||
|
||||
return $this->task_runner;
|
||||
}
|
||||
|
||||
protected function add_flag( $flag ) {
|
||||
update_option( $this->get_plugin_name() . '_' . $this->get_action() . '_' . $flag, 1 );
|
||||
}
|
||||
|
||||
protected function get_flag( $flag ) {
|
||||
return get_option( $this->get_plugin_name() . '_' . $this->get_action() . '_' . $flag );
|
||||
}
|
||||
|
||||
protected function delete_flag( $flag ) {
|
||||
delete_option( $this->get_plugin_name() . '_' . $this->get_action() . '_' . $flag );
|
||||
}
|
||||
|
||||
protected function get_start_action_url() {
|
||||
return wp_nonce_url( add_query_arg( $this->get_action(), 'run' ), $this->get_action() . 'run' );
|
||||
}
|
||||
|
||||
protected function get_continue_action_url() {
|
||||
return wp_nonce_url( add_query_arg( $this->get_action(), 'continue' ), $this->get_action() . 'continue' );
|
||||
}
|
||||
|
||||
private function continue_run() {
|
||||
$runner = $this->get_task_runner();
|
||||
$runner->continue_run();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
/**
|
||||
* Abstract Class PPWP Background Task
|
||||
*/
|
||||
defined ( 'ABSPATH' ) || exit;
|
||||
|
||||
if ( ! class_exists( 'WP_Async_Request', false ) ) {
|
||||
include_once PPW_DIR_PATH . '/includes/libs/wp-background-process/wp-async-request.php';
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WP_Background_Process', false ) ) {
|
||||
include_once PPW_DIR_PATH . '/includes/libs/wp-background-process/wp-background-process.php';
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'PPW_Pro_Background_Task' ) ) {
|
||||
/**
|
||||
* Class PPW_Background_Task
|
||||
*/
|
||||
abstract class PPW_Background_Task extends WP_Background_Process {
|
||||
protected $current_item;
|
||||
|
||||
protected $manager;
|
||||
|
||||
public function __construct( $manager ) {
|
||||
$this->manager = $manager;
|
||||
$this->prefix = 'ppw_' . get_current_blog_id();
|
||||
$this->action = $this->manager->get_action();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch updater
|
||||
*
|
||||
* Updater will still run via cron job if this fails for any reason.
|
||||
*/
|
||||
public function dispatch() {
|
||||
$dispatched = parent::dispatch();
|
||||
|
||||
if ( is_wp_error( $dispatched ) ) {
|
||||
wp_die( ppw_escape_wp_error( $dispatched ) ); // phpcs:ignores -- we already escape the wp_error
|
||||
}
|
||||
}
|
||||
|
||||
public function query_col( $sql ) {
|
||||
global $wpdb;
|
||||
|
||||
// Add Calc.
|
||||
$item = $this->get_current_item();
|
||||
if ( empty( $item['total'] ) ) {
|
||||
$sql = preg_replace( '/^SELECT/', 'SELECT SQL_CALC_FOUND_ROWS', $sql );
|
||||
}
|
||||
|
||||
// Add offset & limit.
|
||||
$sql = preg_replace( '/;$/', '', $sql );
|
||||
$sql .= ' LIMIT %d, %d;';
|
||||
|
||||
$results = $wpdb->get_col( $wpdb->prepare( $sql, $this->get_current_offset(), $this->get_limit() ) ); // phpcs:ignore -- WPCS: unprepared SQL OK.
|
||||
|
||||
if ( ! empty( $results ) ) {
|
||||
$this->set_total();
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_current_item() {
|
||||
error_log( 'Current item: ' . wp_json_encode( $this->current_item ) );
|
||||
return $this->current_item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get batch.
|
||||
*
|
||||
* @return \stdClass Return the first batch from the queue.
|
||||
*/
|
||||
protected function get_batch() {
|
||||
|
||||
$batch = parent::get_batch();
|
||||
|
||||
if (is_object($batch) && isset($batch->data)) {
|
||||
$batch->data = array_filter((array) $batch->data);
|
||||
} else {
|
||||
$batch = new stdClass();
|
||||
}
|
||||
|
||||
return $batch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get batch.
|
||||
*
|
||||
* @return \stdClass Return the first batch from the queue.
|
||||
*/
|
||||
// protected function get_batch() {
|
||||
|
||||
// $batch = parent::get_batch();
|
||||
|
||||
// $batch->data = array_filter((array) $batch->data);
|
||||
|
||||
// return $batch;
|
||||
// }
|
||||
|
||||
|
||||
public function get_current_offset() {
|
||||
$limit = $this->get_limit();
|
||||
|
||||
return ( $this->current_item['iterate_num'] - 1 ) * $limit;
|
||||
}
|
||||
|
||||
public function get_limit() {
|
||||
return $this->manager->get_query_limit();
|
||||
}
|
||||
|
||||
public function set_total() {
|
||||
global $wpdb;
|
||||
|
||||
if ( empty( $this->current_item['total'] ) ) {
|
||||
$total_rows = $wpdb->get_var( 'SELECT FOUND_ROWS();' ); // phpcs:ignore -- WPCS: db call ok. cache ok.
|
||||
$total_iterates = ceil( $total_rows / $this->get_limit() );
|
||||
$this->current_item['total'] = $total_iterates;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete
|
||||
*
|
||||
* Override if applicable, but ensure that the below actions are
|
||||
* performed, or, call parent::complete().
|
||||
*/
|
||||
protected function complete() {
|
||||
$this->manager->on_runner_complete( true );
|
||||
|
||||
parent::complete();
|
||||
}
|
||||
|
||||
public function continue_run() {
|
||||
// Used to fire an action added in WP_Background_Process::_construct() that calls WP_Background_Process::handle_cron_healthcheck().
|
||||
// This method will make sure the database updates are executed even if cron is disabled. Nothing will happen if the updates are already running.
|
||||
do_action( $this->cron_hook_identifier );
|
||||
}
|
||||
|
||||
protected function task( $item ) {
|
||||
$result = false;
|
||||
|
||||
if ( is_callable( $item['callback'] ) ) {
|
||||
$result = (bool) call_user_func( $item['callback'], $this );
|
||||
}
|
||||
|
||||
return $result ? $item : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* See if the batch limit has been exceeded.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function batch_limit_exceeded() {
|
||||
return $this->time_exceeded() || $this->memory_exceeded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle.
|
||||
*
|
||||
* Pass each queue item to the task handler, while remaining
|
||||
* within server memory and time limit constraints.
|
||||
*/
|
||||
protected function handle() {
|
||||
$this->manager->on_runner_start();
|
||||
|
||||
$this->lock_process();
|
||||
|
||||
do {
|
||||
$batch = $this->get_batch();
|
||||
|
||||
foreach ( $batch->data as $key => $value ) {
|
||||
$task = $this->task( $value );
|
||||
|
||||
if ( false !== $task ) {
|
||||
$batch->data[ $key ] = $task;
|
||||
} else {
|
||||
unset( $batch->data[ $key ] );
|
||||
}
|
||||
|
||||
if ( $this->batch_limit_exceeded() ) {
|
||||
// Batch limits reached.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Update or delete current batch.
|
||||
if ( ! empty( $batch->data ) ) {
|
||||
$this->update( $batch->key, $batch->data );
|
||||
} else {
|
||||
$this->delete( $batch->key );
|
||||
}
|
||||
} while ( ! $this->batch_limit_exceeded() && ! $this->is_queue_empty() );
|
||||
|
||||
$this->unlock_process();
|
||||
|
||||
// Start next batch or complete process.
|
||||
if ( ! $this->is_queue_empty() ) {
|
||||
$this->dispatch();
|
||||
} else {
|
||||
$this->complete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the protected `is_process_running` method as a public method.
|
||||
* @return bool
|
||||
*/
|
||||
public function is_process_locked() {
|
||||
return $this->is_process_running();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is running?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_running() {
|
||||
return false === $this->is_queue_empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule cron healthcheck.
|
||||
*
|
||||
* @param array $schedules Schedules.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function schedule_cron_healthcheck( $schedules ) {
|
||||
$interval = apply_filters( $this->identifier . '_cron_interval', 5 );
|
||||
|
||||
// Adds every 5 minutes to the existing schedules.
|
||||
$schedules[ $this->identifier . '_cron_interval' ] = array(
|
||||
'interval' => MINUTE_IN_SECONDS * $interval,
|
||||
/* translators: %d: interval */
|
||||
'display' => sprintf( __( 'Every %d minutes', 'password-protect-page' ), $interval ),
|
||||
);
|
||||
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all batches.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function delete_all_batches() {
|
||||
global $wpdb;
|
||||
|
||||
$table = $wpdb->options;
|
||||
$column = 'option_name';
|
||||
|
||||
if ( is_multisite() ) {
|
||||
$table = $wpdb->sitemeta;
|
||||
$column = 'meta_key';
|
||||
}
|
||||
|
||||
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
|
||||
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$table} WHERE {$column} LIKE %s", $key ) ); // @codingStandardsIgnoreLine.
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kill process.
|
||||
*
|
||||
* Stop processing queue items, clear cronjob and delete all batches.
|
||||
*/
|
||||
public function kill_process() {
|
||||
if ( ! $this->is_queue_empty() ) {
|
||||
$this->delete_all_batches();
|
||||
wp_clear_scheduled_hook( $this->cron_hook_identifier );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle cron healthcheck
|
||||
*
|
||||
* Restart the background process if not already running
|
||||
* and data exists in the queue.
|
||||
*/
|
||||
public function handle_cron_healthcheck() {
|
||||
error_log( 'Checking health-check: ' . wp_json_encode( 'Hello World' ) );
|
||||
if ( $this->is_process_running() ) {
|
||||
error_log( 'PPWP - Background process is running' );
|
||||
// Background process already running.
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $this->is_queue_empty() ) {
|
||||
// No data to process.
|
||||
$this->clear_scheduled_event();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->handle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedele Event
|
||||
*/
|
||||
protected function schedule_event() {
|
||||
if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
|
||||
wp_schedule_event( time() + 20, $this->cron_interval_identifier, $this->cron_hook_identifier );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
/**
|
||||
* Abstract Class PPWP Migration Manager
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'PPW_Migration_Manager' ) ) {
|
||||
abstract class PPW_Migration_Manager extends PPW_Background_Task_Manager {
|
||||
|
||||
abstract public function get_migrations_class();
|
||||
|
||||
abstract public function get_migration_label();
|
||||
|
||||
abstract public function get_success_message();
|
||||
|
||||
public function __construct() {
|
||||
$this->handle_admin_notices();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin Notice Handling
|
||||
*/
|
||||
protected function handle_admin_notices() {
|
||||
$action = 'admin_notices';
|
||||
|
||||
if ( is_admin() && $this->get_flag( 'completed' ) ) {
|
||||
add_action( $action, array( $this, 'admin_notice_upgrade_is_completed' ) );
|
||||
}
|
||||
|
||||
$migration = $this->get_task_runner();
|
||||
|
||||
if ( $migration->is_running() ) {
|
||||
add_action( $action, array( $this, 'admin_notice_upgrade_is_running' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PPW_Migration
|
||||
*/
|
||||
public function get_task_runner_class() {
|
||||
return 'PPW_Migration';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Query Limit
|
||||
*/
|
||||
public function get_query_limit() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Boolian value of Migration event
|
||||
*/
|
||||
public function should_migrate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runner Complete
|
||||
* @param boolian $did_task Deafult is False
|
||||
*/
|
||||
public function on_runner_complete( $did_tasks = false ) {
|
||||
// Implement log here
|
||||
if ( $did_tasks ) {
|
||||
$this->add_flag( 'completed' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Run
|
||||
*/
|
||||
public function start_run() {
|
||||
$updater = $this->get_task_runner();
|
||||
|
||||
if ( $updater->is_running() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$upgrade_callbacks = $this->get_migration_callbacks();
|
||||
|
||||
if ( empty( $upgrade_callbacks ) ) {
|
||||
$this->on_runner_complete();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $upgrade_callbacks as $callback ) {
|
||||
$updater->push_to_queue(
|
||||
array(
|
||||
'callback' => $callback,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$updater->save()->dispatch();
|
||||
|
||||
// Use log here
|
||||
}
|
||||
|
||||
/**
|
||||
* Migration Callback
|
||||
* @return array $callbacks Callbacks
|
||||
*/
|
||||
public function get_migration_callbacks() {
|
||||
$prefix = 'migrate_v_';
|
||||
$migrations_class = $this->get_migrations_class();
|
||||
$migration_reflection = new ReflectionClass( $migrations_class );
|
||||
$callbacks = array();
|
||||
|
||||
$methods = $migration_reflection->getMethods();
|
||||
foreach ( $methods as $method ) {
|
||||
$method_name = $method->getName();
|
||||
if ( false === strpos( $method_name, $prefix ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! preg_match_all( "/$prefix(\d+_\d+_\d+)/", $method_name, $matches ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$method_version = str_replace( '_', '.', $matches[1][0] );
|
||||
|
||||
if ( ! version_compare( $method_version, PPW_VERSION, '>' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$callbacks[] = array( $migrations_class, $method_name );
|
||||
}
|
||||
|
||||
return $callbacks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin Notice
|
||||
*/
|
||||
public function admin_notice_upgrade_is_running() {
|
||||
$upgrade_link = $this->get_continue_action_url();
|
||||
$message = '<p>' . sprintf( __( '%s To keep password protecting your private content, we have to <a href="https://passwordprotectwp.com/password-migration/" target="_blank" rel="noopener noreferrer">migrate your passwords</a> to our plugin. The migration process is running in the background.', 'password-protect-page' ), $this->get_updater_label() ) . '</p>';
|
||||
$message .= '<p>' . sprintf( 'Taking a while? <a href="%s" class="button-primary">Click here to run it now</a>', $upgrade_link ) . '</p>';
|
||||
echo '<div class="notice notice-warning">' . $message . '</div>'; // phpcs:ignore -- we don’t need to escape for this
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin Notice success message
|
||||
*/
|
||||
public function admin_notice_upgrade_is_completed() {
|
||||
$this->delete_flag( 'completed' );
|
||||
$message = $this->get_success_message();
|
||||
if ( ! empty( $message ) ) {
|
||||
echo '<div class="notice notice-success">' . $message . '</div>'; // phpcs:ignore -- we don’t need to escape for this
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* Abstract Class for PPWP Module
|
||||
*/
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'PPW_Module' ) ) {
|
||||
abstract class PPW_Module {
|
||||
/**
|
||||
* Get module name.
|
||||
*
|
||||
* Retrieve the module name.
|
||||
*
|
||||
* @since 1.7.0
|
||||
* @access public
|
||||
* @abstract
|
||||
*
|
||||
* @return string Module name.
|
||||
*/
|
||||
abstract public function get_name();
|
||||
|
||||
/**
|
||||
* Instance.
|
||||
*
|
||||
* Ensures only one instance of the module class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.7.0
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @return Module An instance of the class.
|
||||
*/
|
||||
public static function instance() {
|
||||
$class_name = static::class_name();
|
||||
|
||||
if ( empty( static::$_instances[ $class_name ] ) ) {
|
||||
static::$_instances[ $class_name ] = new static();
|
||||
}
|
||||
|
||||
return static::$_instances[ $class_name ];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* PPWP Service Interface
|
||||
*/
|
||||
if ( ! interface_exists( 'PPW_Service_Interfaces' ) ) {
|
||||
interface PPW_Service_Interfaces {
|
||||
|
||||
/**
|
||||
* Check content is protected
|
||||
*
|
||||
* @param $post_id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function is_protected_content( $post_id );
|
||||
|
||||
/**
|
||||
* Check password is valid
|
||||
*
|
||||
* @param $password
|
||||
* @param $post_id
|
||||
* @param $current_roles
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function is_valid_password( $password, $post_id, $current_roles );
|
||||
|
||||
/**
|
||||
* Set password to cookie
|
||||
*
|
||||
* @param $password
|
||||
* @param $cookie_name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function set_password_to_cookie( $password, $cookie_name );
|
||||
|
||||
/**
|
||||
* Check whether the current cookie is valid
|
||||
*
|
||||
* @param $post_id
|
||||
* @param $passwords
|
||||
* @param $cookie_name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function is_valid_cookie( $post_id, $passwords, $cookie_name );
|
||||
|
||||
/**
|
||||
* Redirect after enter password
|
||||
*
|
||||
* @param $is_valid
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle_redirect_after_enter_password( $is_valid );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/* Single Password Form js*/
|
||||
|
||||
(function ($) {
|
||||
$(document).ready(function () {
|
||||
$('form.ppw-post-password-form.post-password-form').bind('submit', handleSubmitBtn);
|
||||
});
|
||||
|
||||
function handleSubmitBtn(evt) {
|
||||
evt.preventDefault();
|
||||
$form = $(this);
|
||||
$inputs = $form.find('input, textarea');
|
||||
var values = {};
|
||||
var $submitBtn = {};
|
||||
$inputs.each(function() {
|
||||
if ( 'Submit' !== this.name ) {
|
||||
if ($(this).prop('type') === 'checkbox' && !$(this).prop('checked')) {
|
||||
return;
|
||||
}
|
||||
values[this.name] = $(this).val();
|
||||
} else {
|
||||
$submitBtn = $(this);
|
||||
}
|
||||
});
|
||||
values['nonce'] = ppw_data.nonce;
|
||||
values['action'] = 'ppw_validate_password';
|
||||
|
||||
$submitBtn.prop("disabled", true);
|
||||
sendRequestToValidatePassword(
|
||||
values,
|
||||
function(data, error) {
|
||||
$submitBtn.prop("disabled", false);
|
||||
var $message = $form.find('div.ppw-ppf-error-msg');
|
||||
if (error) {
|
||||
if ($message.length === 0) {
|
||||
var message = error.responseJSON && error.responseJSON.message ? error.responseJSON.message : 'Please enter the correct password!';
|
||||
$form.append('<div class="ppwp-wrong-pw-error ppw-ppf-error-msg">' + message + '</div>');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.redirect) {
|
||||
window.location.href = data['redirect_to'];
|
||||
return;
|
||||
}
|
||||
|
||||
$message.remove();
|
||||
$form.parent().replaceWith(data.post_content)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function sendRequestToValidatePassword(_data, cb) {
|
||||
$.ajax({
|
||||
url: ppw_data.ajaxUrl,
|
||||
type: 'POST',
|
||||
data: _data,
|
||||
success: function (data) {
|
||||
cb(data, null);
|
||||
},
|
||||
error: function (error) {
|
||||
cb(null, error);
|
||||
},
|
||||
timeout: 10000
|
||||
})
|
||||
}
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
class PPW_Beaver_Loader {
|
||||
/**
|
||||
* Instance of PPW_Beaver_Loader class.
|
||||
*
|
||||
* @var PPW_Beaver_Loader
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* PPW_Beaver_Loader constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'plugins_loaded', array( $this, 'setup_hooks' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup hooks.
|
||||
*/
|
||||
public function setup_hooks() {
|
||||
if ( ! class_exists( 'FLBuilder' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_filter( 'fl_builder_custom_fields', array( $this, 'register_fields' ) );
|
||||
|
||||
// Load custom modules.
|
||||
add_action( 'init', array( $this, 'load_modules' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get instance
|
||||
*
|
||||
* @return PPW_Beaver_Loader
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( is_null( self::$instance ) ) {
|
||||
// Use static instead of self due to the inheritance later.
|
||||
// For example: ChildSC extends this class, when we call get_instance
|
||||
// it will return the object of child class. On the other hand, self function
|
||||
// will return the object of base class.
|
||||
self::$instance = new static();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load modules
|
||||
*/
|
||||
public function load_modules() {
|
||||
require_once __DIR__ . '/modules/ppw-individual-page/class-ppw-module.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Register custom fields.
|
||||
*
|
||||
* @param array $fields Fields.
|
||||
*
|
||||
* @return array Fields.
|
||||
*/
|
||||
public function register_fields( $fields ) {
|
||||
$fields['input-number'] = PPW_DIR_PATH . 'includes/addons/beaver-builder/fields/input-number.php';
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<div class="fl-compound-field-setting fl-animation-field-delay" style="width: 40%">
|
||||
<div class="fl-unit-field-inputs">
|
||||
<div class="fl-unit-field-input">
|
||||
<input type="number" name="{{data.name}}" value="{{data.value}}" oninput="(validity.valid)||(value='');" step="1" min="1"/>
|
||||
</div>
|
||||
<div class="fl-unit-field-input fl-unit-field-unit-select">
|
||||
<div class="fl-field-unit-select">hour(s)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
class PPWBB_Shortcode_Module extends FLBuilderModule {
|
||||
/**
|
||||
* PPWBB_Individual_Content_Module constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
array(
|
||||
'name' => __( 'Password Protect WordPress (PPWP)', 'password-protect-page' ),
|
||||
'description' => __( 'Password protected content', 'password-protect-page' ),
|
||||
'category' => __( 'Partial Content Protection', 'password-protect-page' ),
|
||||
'dir' => PPW_DIR_PATH . 'includes/addons/beaver-builder/modules/ppw-individual-page/',
|
||||
'url' => PPW_DIR_URL . 'includes/addons/beaver-builder/modules/ppw-individual-page/',
|
||||
'icon' => 'editor-code.svg'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function ppwbb_load_individual_content_module() {
|
||||
$raw_roles = apply_filters(
|
||||
'ppw_supported_white_list_roles',
|
||||
array(
|
||||
'administrator',
|
||||
'editor',
|
||||
'author',
|
||||
'contributor',
|
||||
'subscriber',
|
||||
)
|
||||
);
|
||||
|
||||
$role_options = array_reduce(
|
||||
$raw_roles,
|
||||
function ( $carry, $value ) {
|
||||
$carry[ $value ] = __( $value, 'password-protect-page' );
|
||||
|
||||
return $carry;
|
||||
},
|
||||
array()
|
||||
);
|
||||
|
||||
$general_fields = array(
|
||||
'ppwp_passwords' => array(
|
||||
'type' => 'text',
|
||||
'label' => __( 'Passwords', 'password-protect-page' ),
|
||||
'placeholder' => __( 'Enter your password, e.g. password1 password2', 'password-protect-page' ),
|
||||
'description' => 'Multiple passwords are separated by space, case-sensitivity, no more than 100 characters and don’t contain [, ], “, ‘',
|
||||
'default' => 'password1 password2',
|
||||
),
|
||||
'ppwp_whitelisted_roles' => array(
|
||||
'type' => 'select',
|
||||
'label' => __( 'Whitelisted Roles', 'password-protect-page' ),
|
||||
'description' => 'Select user roles who can access protected area without having to enter passwords',
|
||||
'options' => $role_options,
|
||||
'multi-select' => true,
|
||||
),
|
||||
'ppwp_protected_content' => array(
|
||||
'type' => 'editor',
|
||||
'label' => __( 'Protected Content', 'password-protect-page' ),
|
||||
'default' => __( 'This is your protected content.', 'password-protect-page' ),
|
||||
'rows' => '6',
|
||||
),
|
||||
);
|
||||
|
||||
$general_fields = apply_filters( PPW_Constants::HOOK_SHORTCODE_BEAVER_BUILDER_GENERAL_FIELDS, $general_fields );
|
||||
|
||||
$instruction_fields = array(
|
||||
'ppwp_headline' => array(
|
||||
'type' => 'text',
|
||||
'label' => __( 'Headline', 'password-protect-page' ),
|
||||
'default' => __( PPW_Constants::DEFAULT_SHORTCODE_HEADLINE, 'password-protect-page' ),
|
||||
|
||||
),
|
||||
'ppwp_placeholder' => array(
|
||||
'type' => 'text',
|
||||
'label' => __( 'Placeholder', 'password-protect-page' ),
|
||||
'default' => __( '', 'password-protect-page' ),
|
||||
),
|
||||
'ppwp_button' => array(
|
||||
'type' => 'text',
|
||||
'label' => __( 'Button', 'password-protect-page' ),
|
||||
'default' => __( PPW_Constants::DEFAULT_SHORTCODE_BUTTON, 'password-protect-page' ),
|
||||
),
|
||||
'ppwp_description' => array(
|
||||
'type' => 'editor',
|
||||
'label' => __( 'Description', 'password-protect-page' ),
|
||||
'default' => __( PPW_Constants::DEFAULT_SHORTCODE_DESCRIPTION, 'password-protect-page' ),
|
||||
'rows' => '6',
|
||||
),
|
||||
);
|
||||
|
||||
$instruction_fields = apply_filters( PPW_Constants::HOOK_SHORTCODE_BEAVER_BUILDER_INSTRUCTION_FIELDS, $instruction_fields );
|
||||
|
||||
$form = array(
|
||||
'general' =>
|
||||
array(
|
||||
'title' => __( 'Shortcode', 'password-protect-page' ),
|
||||
'sections' => array(
|
||||
'general' => array(
|
||||
'title' => __( 'Protection', 'password-protect-page' ),
|
||||
'fields' => $general_fields,
|
||||
),
|
||||
'instruction' => array(
|
||||
'title' => __( 'Password Form', 'password-protect-page' ),
|
||||
'fields' => $instruction_fields,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$form = apply_filters( PPW_Constants::HOOK_SHORTCODE_BEAVER_BUILDER_FIELDS, $form );
|
||||
|
||||
FLBuilder::register_module(
|
||||
'PPWBB_Shortcode_Module',
|
||||
$form
|
||||
);
|
||||
}
|
||||
|
||||
ppwbb_load_individual_content_module();
|
||||
@@ -0,0 +1,8 @@
|
||||
#fl-field-ppwp_passwords .fl-field-description, #fl-field-ppwp_whitelisted_roles .fl-field-description {
|
||||
background: #f0f0f0;
|
||||
color: #333 !important;
|
||||
display: block;
|
||||
float: none;
|
||||
margin: 10px 0 0 0;
|
||||
padding: 10px;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
|
||||
$shortcode = '[ppwp passwords="' . $settings->ppwp_passwords . '"';
|
||||
|
||||
if ( ! empty( $settings->ppwp_headline ) ) {
|
||||
$shortcode .= ' headline="' . esc_html__($settings->ppwp_headline) . '"';
|
||||
}
|
||||
|
||||
if ( ! empty( $settings->ppwp_description ) ) {
|
||||
$shortcode .= ' description="' . esc_html__( $settings->ppwp_description ) . '"';
|
||||
}
|
||||
|
||||
if ( ! empty( $settings->ppwp_placeholder ) ) {
|
||||
$shortcode .= ' placeholder="' . esc_html__( $settings->ppwp_placeholder ) . '"';
|
||||
}
|
||||
|
||||
if ( ! empty( $settings->ppwp_button ) ) {
|
||||
$shortcode .= ' button="' . esc_html__( $settings->ppwp_button ) . '"';
|
||||
}
|
||||
|
||||
if ( ! empty( $settings->ppwp_cookie ) ) {
|
||||
$shortcode .= ' cookie="' . absint( $settings->ppwp_cookie ) . '"';
|
||||
}
|
||||
|
||||
if ( ! empty( $settings->ppwp_download_limit ) ) {
|
||||
$shortcode .= ' download_limit="' . absint( $settings->ppwp_download_limit ) . '"';
|
||||
}
|
||||
|
||||
if ( is_array( $settings->ppwp_whitelisted_roles ) && count( $settings->ppwp_whitelisted_roles ) > 0 ) {
|
||||
$whitelisted_roles = implode( ',', $settings->ppwp_whitelisted_roles );
|
||||
$shortcode .= ' whitelisted_roles="' . $whitelisted_roles . '"';
|
||||
}
|
||||
|
||||
$shortcode = apply_filters( PPW_Constants::HOOK_SHORTCODE_BEAVER_BUILDER_ATTRIBUTES, $shortcode, $settings );
|
||||
|
||||
$shortcode .= ']';
|
||||
|
||||
echo '<div class="description">' . $shortcode . $settings->ppwp_protected_content . '[/ppwp]' . '</div>'; // phpcs:ignores -- we already escape inside the $shortcode.
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'PPW_Elementor' ) ) {
|
||||
class PPW_Elementor {
|
||||
/**
|
||||
* The loader that's responsible for maintaining and registering all hooks that power
|
||||
* the plugin.
|
||||
*
|
||||
* @access protected
|
||||
* @var PPW_Loader $loader Maintains and registers all hooks for the plugin.
|
||||
*/
|
||||
protected $loader;
|
||||
/**
|
||||
* Minimum elementor version.
|
||||
*
|
||||
* @var PPW_Elementor
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
const MINIMUM_ELEMENTOR_VERSION = '2.0.0';
|
||||
|
||||
const MINIMUM_PPW_FREE_VERSION = '1.2.3.3';
|
||||
|
||||
/**
|
||||
* Get instance.
|
||||
*
|
||||
* @param PPW_Loader $loader Maintains and registers all hooks for the plugin.
|
||||
*
|
||||
* @return PPW_Elementor
|
||||
*/
|
||||
public static function get_instance( $loader ) {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self( $loader );
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param PPW_Loader $loader Maintains and registers all hooks for the plugin.
|
||||
*
|
||||
* PPW_Elementor constructor.
|
||||
*/
|
||||
public function __construct( $loader ) {
|
||||
$this->loader = $loader;
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Elementor hooks.
|
||||
*/
|
||||
public function init() {
|
||||
if ( ! did_action( 'elementor/loaded' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) || ! version_compare( PPW_VERSION, self::MINIMUM_PPW_FREE_VERSION, '>=' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->loader->add_action( 'elementor/widgets/widgets_registered', $this, 'register_widgets' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register widgets.
|
||||
*/
|
||||
public function register_widgets() {
|
||||
$supported_pro_version = array( '1.1.5', '1.1.5.1' );
|
||||
if ( defined( 'PPW_PRO_VERSION' ) && in_array( PPW_PRO_VERSION, $supported_pro_version, true ) && is_pro_active_and_valid_license() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Include widget files.
|
||||
require_once __DIR__ . '/widgets/class-ppw-elementor-widget-shortcode.php';
|
||||
require_once __DIR__ . '/widgets/class-ppw-elementor-advance-widget-shortcode.php';
|
||||
|
||||
// Register widget.
|
||||
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new PPW_Shortcode_Widget() );
|
||||
// Handle hooks from origin widget to add more features.
|
||||
$advance_widget = new PPW_Shortcode_Advance_Widget();
|
||||
$advance_widget->init();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
use Elementor\Plugin;
|
||||
|
||||
if ( ! class_exists( 'PPW_Shortcode_Advance_Widget' ) ) {
|
||||
/**
|
||||
* Advance Elementor ShortCode Widget
|
||||
*
|
||||
* @since 1.4.5
|
||||
*
|
||||
* Class PPW_Shortcode_Advance_Widget
|
||||
*/
|
||||
class PPW_Shortcode_Advance_Widget {
|
||||
/**
|
||||
* Register hooks.
|
||||
*/
|
||||
public function init() {
|
||||
add_filter( PPW_Constants::HOOK_SHORTCODE_ELEMENTOR_CONTENT, array( $this, 'handle_elementor_show_content_option' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle elementor content with the new attribute "Show Content"
|
||||
*
|
||||
* @param string $content The current content.
|
||||
* @param array $settings The setting array includes:
|
||||
* string ppwp_protected_content.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function handle_elementor_show_content_option( $content, $settings ) {
|
||||
if ( ! $this->is_show_content_enabled( $settings ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
return apply_filters( PPW_Constants::HOOK_SHORTCODE_ELEMENTOR_PREVIEW_CONTENT, $settings['ppwp_protected_content'], $content, $settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the ppwp_show_content option is enabled.
|
||||
*
|
||||
* @param array $settings The Elementor widget settings (refer to handle_elementor_show_content_option function).
|
||||
*
|
||||
* @return bool True if the value equals to 'yes'.
|
||||
*/
|
||||
private function is_show_content_enabled( $settings ) {
|
||||
if ( ! Plugin::$instance->editor->is_edit_mode() ) {
|
||||
return false;
|
||||
}
|
||||
return isset( $settings['ppwp_show_content'] ) && 'yes' === $settings['ppwp_show_content'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,319 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'PPW_Shortcode_Widget' ) ) {
|
||||
class PPW_Shortcode_Widget extends \Elementor\Widget_Base {
|
||||
|
||||
/**
|
||||
* Get element name.
|
||||
*
|
||||
* Retrieve the element name.
|
||||
*
|
||||
* @return string The name.
|
||||
* @since 1.4.0
|
||||
* @access public
|
||||
*/
|
||||
public function get_name() {
|
||||
return 'ppwp';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get skin title.
|
||||
*
|
||||
* Retrieve the skin title.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
public function get_title() {
|
||||
return __( 'Password Protection (PPWP)', 'password-protect-page' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get widget icon.
|
||||
*
|
||||
* Retrieve the widget icon.
|
||||
*
|
||||
* @return string Widget icon.
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
public function get_icon() {
|
||||
return 'fas fa-shield-alt';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get widget categories.
|
||||
*
|
||||
* Retrieve the widget categories.
|
||||
*
|
||||
* @return array Widget categories.
|
||||
* @since 1.0.10
|
||||
* @access public
|
||||
*/
|
||||
public function get_categories() {
|
||||
return array( 'general' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Controls to Widgets
|
||||
*/
|
||||
protected function _register_controls() { //phpcs:ignore -- this is not our function
|
||||
$is_gold_activate = defined( 'PDA_GOLD_V3_VERSION' );
|
||||
$is_ppwp_pro_activate = is_pro_active_and_valid_license();
|
||||
$roles = array();
|
||||
$raw_roles = apply_filters(
|
||||
'ppw_supported_white_list_roles',
|
||||
array(
|
||||
'administrator',
|
||||
'editor',
|
||||
'author',
|
||||
'contributor',
|
||||
'subscriber',
|
||||
)
|
||||
);
|
||||
foreach ( $raw_roles as $value ) {
|
||||
$roles[ $value ] = $value;
|
||||
}
|
||||
$this->start_controls_section(
|
||||
'ppwp_section',
|
||||
array(
|
||||
'label' => __( 'PPWP Shortcode', 'password-protect-page' ),
|
||||
)
|
||||
);
|
||||
|
||||
$controls = array(
|
||||
array(
|
||||
'key' => 'ppwp_protect_options',
|
||||
'value' => array(
|
||||
'label' => __( 'Partial Content Protection', 'password-protect-page' ),
|
||||
'type' => \Elementor\Controls_Manager::HEADING,
|
||||
'separator' => 'before',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'key' => 'ppwp_passwords',
|
||||
'value' => array(
|
||||
'label' => __( 'Passwords', 'password-protect-page' ),
|
||||
'type' => \Elementor\Controls_Manager::TEXT,
|
||||
'placeholder' => __( 'Enter your password, e.g. password1 password2', 'password-protect-page' ),
|
||||
'default' => 'password1 password2',
|
||||
'description' => 'Multiple passwords are separated by space, case-sensitivity, no more than 100 characters and don’t contain [, ], “, ‘',
|
||||
'label_block' => true,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'key' => 'ppwp_whitelisted_roles',
|
||||
'value' => array(
|
||||
'label' => __( 'Whitelisted Roles', 'password-protect-page' ),
|
||||
'type' => \Elementor\Controls_Manager::SELECT2,
|
||||
'placeholder' => __( 'Select whitelisted roles', 'password-protect-page' ),
|
||||
'multiple' => true,
|
||||
'options' => $roles,
|
||||
'description' => 'Select user roles who can access protected area without having to enter passwords',
|
||||
'label_block' => true,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'key' => 'ppwp_protected_content_headline',
|
||||
'value' => array(
|
||||
'label' => __( 'Protected Content', 'password-protect-page' ),
|
||||
'type' => \Elementor\Controls_Manager::HEADING,
|
||||
'separator' => 'before',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'key' => 'ppwp_protected_content',
|
||||
'value' => array(
|
||||
'type' => \Elementor\Controls_Manager::WYSIWYG,
|
||||
'default' => __( 'This is your protected content.', 'password-protect-page' ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'key' => 'ppwp_show_content',
|
||||
'value' => array(
|
||||
'label' => __( 'Show Content', 'password-protect-page' ),
|
||||
'type' => \Elementor\Controls_Manager::SWITCHER,
|
||||
'default' => 'no',
|
||||
'label_on' => __( 'Show', 'essential-addons-elementor' ),
|
||||
'label_off' => __( 'Hide', 'essential-addons-elementor' ),
|
||||
'return_value' => 'yes',
|
||||
'description' => 'You can force show content in order to style them properly.',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'key' => 'ppwp_protect_instruction',
|
||||
'value' => array(
|
||||
'label' => __( 'Password Form', 'password-protect-page' ),
|
||||
'type' => \Elementor\Controls_Manager::HEADING,
|
||||
'separator' => 'before',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'key' => 'ppwp_headline',
|
||||
'value' => array(
|
||||
'label' => __( 'Headline', 'password-protect-page' ),
|
||||
'type' => \Elementor\Controls_Manager::TEXT,
|
||||
'default' => 'Restricted Content',
|
||||
'label_block' => true,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'key' => 'ppwp_label',
|
||||
'value' => array(
|
||||
'label' => __( 'Label', 'password-protect-page' ),
|
||||
'type' => \Elementor\Controls_Manager::TEXT,
|
||||
'default' => PPW_Constants::DEFAULT_SHORTCODE_LABEL,
|
||||
'label_block' => true,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'key' => 'ppwp_description',
|
||||
'value' => array(
|
||||
'label' => __( 'Description', 'password-protect-page' ),
|
||||
'type' => \Elementor\Controls_Manager::WYSIWYG,
|
||||
'default' => 'To view this protected content, enter the password below:',
|
||||
'label_block' => true,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'key' => 'ppwp_placeholder',
|
||||
'value' => array(
|
||||
'label' => __( 'Placeholder', 'password-protect-page' ),
|
||||
'type' => \Elementor\Controls_Manager::TEXT,
|
||||
'default' => '',
|
||||
'label_block' => true,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'key' => 'ppwp_loading',
|
||||
'value' => array(
|
||||
'label' => __( 'Loading', 'password-protect-page' ),
|
||||
'type' => \Elementor\Controls_Manager::TEXT,
|
||||
'default' => PPW_Constants::DEFAULT_SHORTCODE_LOADING,
|
||||
'label_block' => true,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'key' => 'ppwp_button',
|
||||
'value' => array(
|
||||
'label' => __( 'Button', 'password-protect-page' ),
|
||||
'type' => \Elementor\Controls_Manager::TEXT,
|
||||
'default' => 'Enter',
|
||||
'label_block' => true,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'key' => 'ppwp_error_msg',
|
||||
'value' => array(
|
||||
'label' => __( 'Error message', 'password-protect-page' ),
|
||||
'type' => \Elementor\Controls_Manager::TEXT,
|
||||
'default' => PPW_Constants::DEFAULT_SHORTCODE_ERROR_MSG,
|
||||
'label_block' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$controls = apply_filters( PPW_Constants::HOOK_SHORTCODE_ELEMENTOR_CONTROLS, $controls );
|
||||
|
||||
|
||||
foreach ( $controls as $control ) {
|
||||
if ( ! isset( $control['is_hide'] ) || true !== $control['is_hide'] ) {
|
||||
$this->add_control( $control['key'], $control['value'] );
|
||||
}
|
||||
}
|
||||
|
||||
$this->end_controls_section();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render content.
|
||||
*/
|
||||
protected function render() {
|
||||
$shortcode = do_shortcode( $this->generate_shortcode() );
|
||||
?>
|
||||
<div class="elementor-shortcode"><?php echo $shortcode; // phpcs:ignores -- we already escape inside the $shortcode.?></div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render shortcode widget as plain content.
|
||||
*
|
||||
* Override the default behavior by printing the shortcode instead of rendering it.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
*/
|
||||
public function render_plain_content() {
|
||||
// In plain mode, render without shortcode.
|
||||
|
||||
echo $this->generate_shortcode(); // phpcs:ignores -- we already escape inside the $shortcode.
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate PPWP shortcode.
|
||||
*
|
||||
* @return string PPWP Shortcode
|
||||
*/
|
||||
public function generate_shortcode() {
|
||||
$settings = $this->get_settings_for_display();
|
||||
|
||||
$content = apply_filters( PPW_Constants::HOOK_SHORTCODE_ELEMENTOR_CONTENT, '', $settings );
|
||||
if ( ! empty( $content ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$passwords = isset( $settings['ppwp_passwords'] ) ? $settings['ppwp_passwords'] : '';
|
||||
$whitelisted_roles = $this->transform_whitelisted_roles_to_string( $settings );
|
||||
$download_limit = isset( $settings['ppwp_download_limit'] ) ? $settings['ppwp_download_limit'] : '';
|
||||
$cookie = isset( $settings['ppwp_cookie'] ) ? $settings['ppwp_cookie'] : '';
|
||||
$headline = isset( $settings['ppwp_headline'] ) ? $settings['ppwp_headline'] : '';
|
||||
$description = isset( $settings['ppwp_description'] ) ? $settings['ppwp_description'] : '';
|
||||
$label = isset( $settings['ppwp_label'] ) ? $settings['ppwp_label'] : '';
|
||||
$placeholder = isset( $settings['ppwp_placeholder'] ) ? $settings['ppwp_placeholder'] : '';
|
||||
$button = isset( $settings['ppwp_button'] ) ? $settings['ppwp_button'] : '';
|
||||
$error_msg = isset( $settings['ppwp_error_msg'] ) ? $settings['ppwp_error_msg'] : '';
|
||||
$loading = isset( $settings['ppwp_loading'] ) ? $settings['ppwp_loading'] : '';
|
||||
|
||||
$shortcode = sprintf(
|
||||
'[ppwp id="" class="" passwords="%1$s" cookie="%2$s" download_limit="%3$s" whitelisted_roles="%4$s" headline="%5$s" description="%6$s" placeholder="%7$s" button="%8$s" label="%9$s" error_msg="%10$s" loading="%11$s"',
|
||||
$passwords,
|
||||
$cookie,
|
||||
$download_limit,
|
||||
$whitelisted_roles,
|
||||
esc_html__( $headline ),
|
||||
esc_html__( $description ),
|
||||
esc_html__( $placeholder ),
|
||||
esc_html__( $button ),
|
||||
esc_html__( $label ),
|
||||
esc_html__( $error_msg ),
|
||||
esc_html__( $loading )
|
||||
);
|
||||
|
||||
$shortcode = apply_filters( PPW_Constants::HOOK_SHORTCODE_ELEMENTOR_ATTRIBUTES, $shortcode, $settings );
|
||||
|
||||
$shortcode .= ']';
|
||||
|
||||
return $shortcode . $settings['ppwp_protected_content'] . '[/ppwp]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whitelisted roles from Settings.
|
||||
*
|
||||
* @param array $settings The settings.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function transform_whitelisted_roles_to_string( $settings ) {
|
||||
if (
|
||||
! isset( $settings['ppwp_whitelisted_roles'] ) ||
|
||||
! is_array( $settings['ppwp_whitelisted_roles'] ) ||
|
||||
count( $settings['ppwp_whitelisted_roles'] ) === 0
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return implode( ',', $settings['ppwp_whitelisted_roles'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Fired during plugin activation
|
||||
*
|
||||
* @link https://passwordprotectwp.com
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Password_Protect_Page
|
||||
* @subpackage Password_Protect_Page/includes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fired during plugin activation.
|
||||
*
|
||||
* This class defines all code necessary to run during the plugin's activation.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package Password_Protect_Page
|
||||
* @subpackage Password_Protect_Page/includes
|
||||
* @author BWPS <hello@preventdirectaccess.com>
|
||||
*/
|
||||
class PPW_Activator {
|
||||
|
||||
/**
|
||||
* Short Description. (use period)
|
||||
*
|
||||
* Long Description.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function activate() {
|
||||
if ( ! version_compare( PHP_VERSION, '5.6', '>=' ) ) {
|
||||
/* translators: %s: PHP version */
|
||||
$message = sprintf( esc_html__( 'Password Protect WordPress requires PHP version %s+, plugin cannot be activated.', 'password-protect-page' ), '5.6' );
|
||||
$html_message = sprintf( '<div class="error">%s</div>', wpautop( $message ) );
|
||||
wp_die( wp_kses_post( $html_message ) );
|
||||
} elseif ( ! version_compare( get_bloginfo( 'version' ), '4.7', '>=' ) ) {
|
||||
/* translators: %s: PHP version */
|
||||
$message = sprintf( esc_html__( 'Password Protect WordPress requires WordPress version %s+. Because you are using an earlier version, the plugin cannot be activated.', 'password-protect-page' ), '4.7' );
|
||||
$html_message = sprintf( '<div class="error">%s</div>', wpautop( $message ) );
|
||||
wp_die( wp_kses_post( $html_message ) );
|
||||
}
|
||||
|
||||
if ( is_plugin_active( PPW_Constants::PRO_DIRECTORY ) ) {
|
||||
$installed_plugins = get_plugins();
|
||||
$version = $installed_plugins[ PPW_Constants::PRO_DIRECTORY ]['Version'];
|
||||
if ( - 1 === version_compare( $version, '1.1.0' ) ) {
|
||||
wp_die( wp_kses_post( __( 'You need to <a target="_blank" rel="noreferrer noopener" href="https://passwordprotectwp.com/docs/ppwp-pro-free/">update our Pro to its latest version</a> for our Password Protect WordPress plugins to work properly. You <b>must NOT delete</b> the current Free version. Otherwise, you’ll lose all your current settings data.', 'password-protect-page' ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,938 @@
|
||||
<?php
|
||||
/**
|
||||
* Registered PPW API
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'PPW_API' ) ) {
|
||||
/**
|
||||
* API definitions
|
||||
*/
|
||||
class PPW_API {
|
||||
/**
|
||||
* Messages.
|
||||
*/
|
||||
const MESSAGES = array(
|
||||
'PASSWORD_UPDATE_SUCCESSFULLY' => 'Great! You’ve updated the password successfully.',
|
||||
'PASSWORD_UPDATE_FAILURE' => 'Opps! Something went wrong. Please try again.',
|
||||
);
|
||||
|
||||
/**
|
||||
* Register rest routes
|
||||
*/
|
||||
public function register_rest_routes() {
|
||||
register_rest_route(
|
||||
'wppp/v1',
|
||||
'check-content-password/(?P<id>\d+)',
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array(
|
||||
$this,
|
||||
'ppwp_check_content_password',
|
||||
),
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Post ID' ),
|
||||
'sanitize_callback' => 'absint',
|
||||
'type' => 'integer',
|
||||
),
|
||||
'page' => array(
|
||||
'description' => __( 'Page index' ),
|
||||
'sanitize_callback' => 'absint',
|
||||
'type' => 'integer',
|
||||
),
|
||||
'idx' => array(
|
||||
'description' => __( 'Form index' ),
|
||||
'sanitize_callback' => 'absint',
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
'permission_callback' => '__return_true',
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'wppp/v1',
|
||||
'master-passwords',
|
||||
array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array(
|
||||
$this,
|
||||
'ppwp_get_master_passwords',
|
||||
),
|
||||
'permission_callback' => array( $this, 'can_access' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'wppp/v1',
|
||||
'master-passwords',
|
||||
array(
|
||||
'methods' => 'DELETE',
|
||||
'callback' => array(
|
||||
$this,
|
||||
'delete_password',
|
||||
),
|
||||
'permission_callback' => array( $this, 'can_access' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'wppp/v1',
|
||||
'master-passwords',
|
||||
array(
|
||||
'methods' => 'PUT',
|
||||
'callback' => array(
|
||||
$this,
|
||||
'update_password',
|
||||
),
|
||||
'permission_callback' => array( $this, 'can_access' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'wppp/v1',
|
||||
'master-passwords/status',
|
||||
array(
|
||||
'methods' => 'PUT',
|
||||
'callback' => array(
|
||||
$this,
|
||||
'change_status',
|
||||
),
|
||||
'permission_callback' => array( $this, 'can_access' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'wppp/v1',
|
||||
'master-passwords',
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array(
|
||||
$this,
|
||||
'add_new_master_password',
|
||||
),
|
||||
'permission_callback' => array( $this, 'can_access' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'wppp/v1',
|
||||
'/master-passwords/bulk-delete',
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array(
|
||||
$this,
|
||||
'bulk_delete_master_passwords',
|
||||
),
|
||||
'permission_callback' => array( $this, 'can_access' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'wppp/v1',
|
||||
'/master-passwords/all-expired-delete',
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array(
|
||||
$this,
|
||||
'all_expired_delete_master_passwords',
|
||||
),
|
||||
'permission_callback' => array( $this, 'can_access' ),
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
register_rest_route(
|
||||
'wppp/v1',
|
||||
'validate-password',
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array(
|
||||
$this,
|
||||
'validate_password',
|
||||
),
|
||||
'permission_callback' => '__return_true',
|
||||
'show_in_index' => false
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'wppp/v1',
|
||||
'pcp/(?P<id>\d+)/settings',
|
||||
array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array(
|
||||
$this,
|
||||
'get_pcp_settings',
|
||||
),
|
||||
'permission_callback' => array( $this, 'can_access' ),
|
||||
'show_in_index' => false,
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
'wppp/v1',
|
||||
'pcp/(?P<id>\d+)/settings',
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array(
|
||||
$this,
|
||||
'update_pcp_settings',
|
||||
),
|
||||
'permission_callback' => array( $this, 'can_access' ),
|
||||
'show_in_index' => false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function can_access() {
|
||||
return ppw_allow_manage_passwords();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Master Passwords.
|
||||
*/
|
||||
public function ppwp_get_master_passwords() {
|
||||
$ppwp_db = new PPW_Repository_Passwords();
|
||||
wp_send_json(
|
||||
array(
|
||||
'result' => $ppwp_db->get_master_passwords_info(),
|
||||
'success' => true,
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expired time stamp
|
||||
*
|
||||
* @param string $days_to_expired Number of days.
|
||||
*
|
||||
* @return int
|
||||
* @throws Exception Emits Exception in case of an error with DateTime.
|
||||
*/
|
||||
private function get_expired_time_stamp( $days_to_expired ) {
|
||||
$curr_date = new DateTime();
|
||||
$expired_date = $curr_date->modify( intval( $days_to_expired ) . ' day' );
|
||||
|
||||
return $expired_date->getTimestamp();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add new variable.
|
||||
*
|
||||
* @param WP_REST_Request $request The REST API request to process.
|
||||
*
|
||||
* @return WP_REST_Response The REST response.
|
||||
* @throws Exception Exception.
|
||||
*/
|
||||
public function add_new_master_password( $request ) {
|
||||
$passwords = $request->get_param( 'password' );
|
||||
$usage_limit = $request->get_param( 'usage_limit' );
|
||||
$expired_dates = $request->get_param( 'expired_dates' );
|
||||
$role_type = $request->get_param( 'role_type' );
|
||||
$roles_selected = $request->get_param( 'roles_selected' );
|
||||
$label = $request->get_param( 'label' );
|
||||
$post_types = $request->get_param( 'post_types' );
|
||||
$protection_types = $request->get_param( 'protection_types' );
|
||||
|
||||
$ppwp_repo = new PPW_Repository_Passwords();
|
||||
|
||||
foreach ( $passwords as $password ) {
|
||||
if ( $ppwp_repo->find_by_master_password( $password ) || '' === $password ) {
|
||||
return wp_send_json(
|
||||
array(
|
||||
'result' => array(),
|
||||
'success' => false,
|
||||
),
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$roles = PPW_Constants::PPW_MASTER_GLOBAL;
|
||||
if ( 'roles' === $role_type ) {
|
||||
$roles = $roles_selected;
|
||||
}
|
||||
|
||||
try {
|
||||
$is_added = false;
|
||||
foreach ( $passwords as $password ) {
|
||||
$is_added = $ppwp_repo->add_new_password(
|
||||
array(
|
||||
'password' => $password,
|
||||
'created_time' => time(),
|
||||
'campaign_app_type' => $roles,
|
||||
'usage_limit' => $usage_limit ? $usage_limit : null,
|
||||
'expired_date' => $expired_dates ? $this->get_expired_time_stamp( $expired_dates ) : null,
|
||||
'label' => $label,
|
||||
'post_types' => $post_types,
|
||||
'protection_types' => $protection_types
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( $is_added ) {
|
||||
return wp_send_json(
|
||||
array(
|
||||
'result' => $is_added,
|
||||
'success' => true,
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
} catch ( Exception $exception ) {
|
||||
return wp_send_json(
|
||||
array(
|
||||
'result' => array(),
|
||||
'success' => false,
|
||||
'message' => $exception->getMessage(),
|
||||
),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
return wp_send_json(
|
||||
array(
|
||||
'result' => array(),
|
||||
'success' => false,
|
||||
),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete password by id.
|
||||
*
|
||||
* @param object $request Request from body.
|
||||
*
|
||||
* @return WP_REST_Response The REST response.
|
||||
*/
|
||||
public function delete_password( $request ) {
|
||||
$id = $request->get_param( 'id' );
|
||||
$ppwp_repo = new PPW_Repository_Passwords();
|
||||
$is_deleted = $ppwp_repo->delete( $id );
|
||||
if ( $is_deleted ) {
|
||||
return wp_send_json(
|
||||
array(
|
||||
'result' => $is_deleted,
|
||||
'success' => true,
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
return wp_send_json(
|
||||
array(
|
||||
'result' => array(),
|
||||
'success' => false,
|
||||
),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk delete master password.
|
||||
*
|
||||
* @param object $request Request from body.
|
||||
*
|
||||
* @return WP_REST_Response The REST response.
|
||||
*/
|
||||
public function bulk_delete_master_passwords( $request ) {
|
||||
$ids = $request->get_param( 'ids' );
|
||||
$ppwp_repo = new PPW_Repository_Passwords();
|
||||
$is_deleted = $ppwp_repo->bulk_delete_passwords( $ids );
|
||||
if ( $is_deleted ) {
|
||||
return wp_send_json(
|
||||
array(
|
||||
'result' => $is_deleted,
|
||||
'success' => true,
|
||||
'message' => 'Great! You’ve deleted the passwords successfully.'
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
return wp_send_json(
|
||||
array(
|
||||
'result' => array(),
|
||||
'success' => false,
|
||||
'message' => ''
|
||||
),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* All Expired delete master password.
|
||||
*
|
||||
* @param object $request Request from body.
|
||||
*
|
||||
* @return WP_REST_Response The REST response.
|
||||
*/
|
||||
public function all_expired_delete_master_passwords( $request ) {
|
||||
$ids = $request->get_param( 'ids' );
|
||||
$campaign_app_type='master_';
|
||||
$ppwp_repo = new PPW_Repository_Passwords();
|
||||
$is_deleted = $ppwp_repo->delete_all_expired_password($ids, $campaign_app_type);
|
||||
|
||||
if ( $is_deleted ) {
|
||||
return wp_send_json(
|
||||
array(
|
||||
'result' => $is_deleted,
|
||||
'success' => true,
|
||||
'message' => 'Great! You’ve deleted all the expired passwords successfully.'
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
return wp_send_json(
|
||||
array(
|
||||
'result' => array(),
|
||||
'success' => false,
|
||||
'message' => 'An error occurred, or no expired passwords were detected.'
|
||||
),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update password by id.
|
||||
*
|
||||
* @param object $request Request from body.
|
||||
*
|
||||
* @return WP_REST_Response The REST response.
|
||||
*/
|
||||
public function update_password( $request ) {
|
||||
$data = $request->get_param( 'data' );
|
||||
$id = $request->get_param( 'id' );
|
||||
$ppwp_repo = new PPW_Repository_Passwords();
|
||||
$is_updated = $ppwp_repo->update_password(
|
||||
$id,
|
||||
$data
|
||||
);
|
||||
if ( $is_updated ) {
|
||||
return wp_send_json(
|
||||
array(
|
||||
'result' => $is_updated,
|
||||
'success' => true,
|
||||
'message' => self::MESSAGES['PASSWORD_UPDATE_SUCCESSFULLY'],
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
return wp_send_json(
|
||||
array(
|
||||
'result' => array(),
|
||||
'success' => false,
|
||||
'message' => self::MESSAGES['PASSWORD_UPDATE_FAILURE'],
|
||||
),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change status by id.
|
||||
*
|
||||
* @param object $request Request from body.
|
||||
*
|
||||
* @return WP_REST_Response The REST response.
|
||||
*/
|
||||
public function change_status( $request ) {
|
||||
$id = $request->get_param( 'id' );
|
||||
$is_activated = $request->get_param( 'is_activated' );
|
||||
$ppwp_repo = new PPW_Repository_Passwords();
|
||||
$is_updated = $ppwp_repo->update_password(
|
||||
$id,
|
||||
array(
|
||||
'is_activated' => $is_activated,
|
||||
)
|
||||
);
|
||||
if ( $is_updated ) {
|
||||
return wp_send_json(
|
||||
array(
|
||||
'result' => $is_updated,
|
||||
'success' => true,
|
||||
'message' => self::MESSAGES['PASSWORD_UPDATE_SUCCESSFULLY'],
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
return wp_send_json(
|
||||
array(
|
||||
'result' => array(),
|
||||
'success' => false,
|
||||
'message' => self::MESSAGES['PASSWORD_UPDATE_FAILURE'],
|
||||
),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checking the content passwords
|
||||
*
|
||||
* @param array $data Post data.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function ppwp_check_content_password( $data ) {
|
||||
do_action( PPW_Constants::HOOK_RESTRICT_CONTENT_BEFORE_CHECK_PWD, $data );
|
||||
|
||||
$result = array(
|
||||
'isValid' => false,
|
||||
'message' => _x( apply_filters( PPW_Constants::HOOK_RESTRICT_CONTENT_ERROR_MESSAGE, PPW_Constants::DEFAULT_WRONG_PASSWORD_MESSAGE ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
|
||||
);
|
||||
|
||||
$is_valid_data = apply_filters( PPW_Constants::HOOK_SHORT_CODE_VALID_POST_DATA, $this->is_valid_data_content_password( $data ) );
|
||||
|
||||
if ( ! $is_valid_data ) {
|
||||
return wp_send_json(
|
||||
$result,
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
$post = get_post( $data['id'] );
|
||||
if ( is_null( $post ) ) {
|
||||
return wp_send_json(
|
||||
$result,
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
$content = apply_filters( PPW_Constants::HOOK_SHORTCODE_CONTENT_SOURCE, $post->post_content, $post, $data );
|
||||
if ( false === $content ) {
|
||||
return wp_send_json(
|
||||
$result,
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! has_shortcode( $content, PPW_Constants::PPW_HOOK_SHORT_CODE_NAME ) ) {
|
||||
return wp_send_json(
|
||||
$result,
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
$matches = ppw_free_search_shortcode_content( $content );
|
||||
$matches = $this->filter_short_code_matches( $matches, PPW_Constants::PPW_HOOK_SHORT_CODE_NAME );
|
||||
|
||||
if ( ! isset( $matches[ $data['idx'] ] ) ) {
|
||||
return wp_send_json(
|
||||
$result,
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
// Get all arguments of shortcode.
|
||||
$shortcode = $matches[ $data['idx'] ];
|
||||
|
||||
if ( PPW_Recaptcha::get_instance()->using_pcp_recaptcha()
|
||||
&& ! PPW_Recaptcha::get_instance()->is_valid_recaptcha() ) {
|
||||
$result['message'] = PPW_Recaptcha::get_instance()->get_error_message();
|
||||
|
||||
return wp_send_json(
|
||||
$result,
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
// Valid passwords.
|
||||
$array_values = ppw_free_valid_pcp_password( $shortcode, $data['pss'] );
|
||||
if ( $array_values['is_valid_password'] ) {
|
||||
$atts = $array_values['atts'];
|
||||
$result['cookie_expired_time'] = $atts['cookie'];
|
||||
$result['isValid'] = true;
|
||||
$result['message'] = '';
|
||||
do_action( PPW_Constants::HOOK_RESTRICT_CONTENT_AFTER_VALID_PWD, $post, $data['pss'] );
|
||||
|
||||
if ( ppw_core_get_setting_type_bool_by_option_name( PPW_Constants::NO_RELOAD_PAGE, PPW_Constants::MISC_OPTIONS ) ) {
|
||||
$post_content = ppw_get_pcp_post_content_with_third_party( $post, $data['idx'] );
|
||||
|
||||
$result['content'] = ! empty( $post_content ) ? $post_content : $shortcode[5];
|
||||
$result['noReload'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Allow custom error message from error_msg shortcode's attribute.
|
||||
if ( isset( $array_values['message'] ) ) {
|
||||
$result['message'] = _x( wp_kses_post( $array_values['message'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' );
|
||||
}
|
||||
|
||||
$result = apply_filters( 'ppw_pcp_api_result', $result, $data['pss'], $post );
|
||||
|
||||
return wp_send_json(
|
||||
$result,
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate input data.
|
||||
*
|
||||
* @param array $data POST data.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_valid_data_content_password( $data ) {
|
||||
return isset( $data['id'] ) && isset( $data['page'] ) && $data['page'] > 0 && isset( $data['formType'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checking the password is valid in short code attribute.
|
||||
* Sample data:
|
||||
* Array
|
||||
* (
|
||||
* [0] => [ppwp passwords="123456 123"]This is the content under Group2[/ppwp]
|
||||
* [1] =>
|
||||
* [2] => ppwp
|
||||
* [3] => passwords="123456 123"
|
||||
* [4] =>
|
||||
* [5] => This is the content under Group2
|
||||
* [6] =>
|
||||
* ).
|
||||
*
|
||||
* @param array $shortcode The found short codes in the content.
|
||||
*
|
||||
* @param string $password Password from request.
|
||||
*
|
||||
* @return array
|
||||
* @deprecated 1.5.2
|
||||
*
|
||||
*/
|
||||
private function handle_valid_password( $shortcode, $password ) {
|
||||
$default_args = array(
|
||||
'is_valid_password' => false,
|
||||
'atts' => array(),
|
||||
);
|
||||
// Check ppwp shortcode exist.
|
||||
if ( PPW_Constants::PPW_HOOK_SHORT_CODE_NAME !== $shortcode[2] || ! isset( $shortcode[3] ) ) {
|
||||
return $default_args;
|
||||
}
|
||||
// Parse shortcode string to array.
|
||||
$parsed_atts = shortcode_parse_atts( trim( $shortcode[3] ) );
|
||||
|
||||
// Get attributes from shortcode.
|
||||
$atts = PPW_Shortcode::get_instance()->get_attributes( $parsed_atts );
|
||||
$passwords = apply_filters( PPW_Constants::HOOK_SHORTCODE_PASSWORDS, array_filter( $atts['passwords'], 'strlen' ), $parsed_atts );
|
||||
|
||||
// Check password exist.
|
||||
if ( in_array( $password, $passwords, true ) ) {
|
||||
$default_args['is_valid_password'] = true;
|
||||
$default_args['atts'] = $atts;
|
||||
}
|
||||
|
||||
if ( isset( $parsed_atts['error_msg'] ) ) {
|
||||
$default_args['message'] = wp_kses_post( $parsed_atts['error_msg'] );
|
||||
}
|
||||
|
||||
return $default_args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search shortcode content
|
||||
*
|
||||
* @param string $content The post content.
|
||||
*
|
||||
* @return mixed
|
||||
* @deprecated 1.5.2
|
||||
*
|
||||
*/
|
||||
private function search_shortcode_content( $content ) {
|
||||
preg_match_all( '/' . get_shortcode_regex( array( 'ppwp' ) ) . '/', $content, $matches, PREG_SET_ORDER );
|
||||
|
||||
return $matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter short code result by name
|
||||
*
|
||||
* @param array $result The result need to filter.
|
||||
* @param string $shortcode_name Short code name.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function filter_short_code_matches( $result, $shortcode_name ) {
|
||||
return array_values(
|
||||
array_filter(
|
||||
$result,
|
||||
function ( $match ) use ( $shortcode_name ) {
|
||||
return isset( $match[2] ) && $shortcode_name === $match[2];
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate post data.
|
||||
*
|
||||
* @param WP_Post|object|int $post WP_Post instance or Post ID/object.
|
||||
*
|
||||
* @return array|bool $elements Elements of post or false on failure.
|
||||
* @since 5.2.0
|
||||
*
|
||||
*/
|
||||
private function generate_postdata( $post ) {
|
||||
|
||||
if ( ! ( $post instanceof WP_Post ) ) {
|
||||
$post = get_post( $post );
|
||||
}
|
||||
|
||||
if ( ! $post ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$id = (int) $post->ID;
|
||||
|
||||
$authordata = get_userdata( $post->post_author );
|
||||
|
||||
$currentday = mysql2date( 'd.m.y', $post->post_date, false );
|
||||
$currentmonth = mysql2date( 'm', $post->post_date, false );
|
||||
$numpages = 1;
|
||||
$multipage = 0;
|
||||
$page = $this->get( 'page' );
|
||||
if ( ! $page ) {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Force full post content when viewing the permalink for the $post,
|
||||
* or when on an RSS feed. Otherwise respect the 'more' tag.
|
||||
*/
|
||||
if ( $post->ID === get_queried_object_id() && ( is_page() || is_single() ) ) {
|
||||
$more = 1;
|
||||
} elseif ( is_feed() ) {
|
||||
$more = 1;
|
||||
} else {
|
||||
$more = 0;
|
||||
}
|
||||
|
||||
$content = $post->post_content;
|
||||
if ( false !== strpos( $content, '<!--nextpage-->' ) ) {
|
||||
$content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content );
|
||||
$content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content );
|
||||
$content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content );
|
||||
|
||||
// Remove the nextpage block delimiters, to avoid invalid block structures in the split content.
|
||||
$content = str_replace( '<!-- wp:nextpage -->', '', $content );
|
||||
$content = str_replace( '<!-- /wp:nextpage -->', '', $content );
|
||||
|
||||
// Ignore nextpage at the beginning of the content.
|
||||
if ( 0 === strpos( $content, '<!--nextpage-->' ) ) {
|
||||
$content = substr( $content, 15 );
|
||||
}
|
||||
|
||||
$pages = explode( '<!--nextpage-->', $content );
|
||||
} else {
|
||||
$pages = array( $post->post_content );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the "pages" derived from splitting the post content.
|
||||
*
|
||||
* "Pages" are determined by splitting the post content based on the presence
|
||||
* of `<!-- nextpage -->` tags.
|
||||
*
|
||||
* @param string[] $pages Array of "pages" from the post content split by `<!-- nextpage -->` tags.
|
||||
* @param WP_Post $post Current post object.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
*/
|
||||
$pages = apply_filters( 'content_pagination', $pages, $post );
|
||||
|
||||
$numpages = count( $pages );
|
||||
|
||||
if ( $numpages > 1 ) {
|
||||
if ( $page > 1 ) {
|
||||
$more = 1;
|
||||
}
|
||||
$multipage = 1;
|
||||
} else {
|
||||
$multipage = 0;
|
||||
}
|
||||
|
||||
$elements = compact( 'id', 'authordata', 'currentday', 'currentmonth', 'page', 'pages', 'multipage', 'more', 'numpages' );
|
||||
|
||||
return $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $request
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public function validate_password( $request ) {
|
||||
$post_id = $request->get_param( 'post_id' );
|
||||
$password = $request->get_param( 'post_password' );
|
||||
$post_id = absint( $post_id );
|
||||
$password = wp_unslash( $password ); // phpcs:ignore -- not sanitize password because we allow all character.
|
||||
|
||||
if ( empty( $post_id ) ) {
|
||||
return new WP_REST_Response(
|
||||
array(
|
||||
'success' => false,
|
||||
'message' => 'Post ID is empty',
|
||||
),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
$post = get_post( $post_id );
|
||||
if ( empty( $post ) ) {
|
||||
return new WP_REST_Response(
|
||||
array(
|
||||
'success' => false,
|
||||
'message' => 'Post not found',
|
||||
),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
$post_content = apply_filters( 'the_content', $post->post_content );
|
||||
$password_service = new PPW_Password_Services();
|
||||
$is_valid = $password_service->is_valid_password_from_request( $post_id, $password );
|
||||
|
||||
if ( ! $is_valid ) {
|
||||
return new WP_REST_Response(
|
||||
array(
|
||||
'success' => false,
|
||||
'message' => ppw_core_get_error_msg( $post_id ),
|
||||
),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
// Don not check post type in PPWP shortcode.
|
||||
add_filter( 'ppw_shortcode_allow_bypass_valid_post_type', '__return_true' );
|
||||
|
||||
return new WP_REST_Response(
|
||||
array(
|
||||
'success' => true,
|
||||
'post_content' => '<div>' . do_shortcode( $post_content ) . '</div>',
|
||||
'message' => 'The password you entered is correct',
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
public function get_pcp_settings( $request ) {
|
||||
$ppwp_db = new PPW_Repository_Passwords();
|
||||
$post_id = $request->get_param( 'id' );
|
||||
$passwords = $ppwp_db->get_passwords_with_type_and_post_id( PPW_Content_Protection::PASSWORD_GLOBAL_TYPE, $post_id, 'password' );
|
||||
$setting = array();
|
||||
if ( count( $passwords ) > 0 ) {
|
||||
$passwords = array_map(
|
||||
function ( $password_info ) {
|
||||
return $password_info->password;
|
||||
},
|
||||
$passwords
|
||||
);
|
||||
$setting['passwords'] = $passwords;
|
||||
} else {
|
||||
$setting['passwords'] = array();
|
||||
}
|
||||
|
||||
return new WP_REST_Response(
|
||||
$setting,
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
public function update_pcp_settings( $request ) {
|
||||
$ppwp_db = new PPW_Repository_Passwords();
|
||||
$ppwp_area = new PPW_Content_Protection();
|
||||
$post_id = $request->get_param( 'id' );
|
||||
$passwords = $request->get_param( 'passwords' );
|
||||
|
||||
$post = get_post( $post_id );
|
||||
if ( ! $ppwp_area->check_area_exist( $post ) ) {
|
||||
return new WP_REST_Response(
|
||||
array(
|
||||
'success' => false,
|
||||
),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
if ( empty( $passwords ) ) {
|
||||
$ppwp_db->delete_passwords_by_post_id( $post_id );
|
||||
|
||||
return new WP_REST_Response(
|
||||
array(
|
||||
'success' => true,
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
$raw_password_dbs = $ppwp_db->get_passwords_with_type_and_post_id( PPW_Content_Protection::PASSWORD_GLOBAL_TYPE, $post_id, 'id, password' );
|
||||
if ( count( $raw_password_dbs ) > 0 ) {
|
||||
$password_dbs = array_map(
|
||||
function ( $password_info ) {
|
||||
return $password_info->password;
|
||||
},
|
||||
$raw_password_dbs
|
||||
);
|
||||
|
||||
$passwords_to_add = array_values( array_diff( $passwords, $password_dbs ) );
|
||||
$passwords_to_delete = array_values( array_diff( $password_dbs, $passwords ) );
|
||||
|
||||
foreach ( $passwords_to_add as $password_to_add ) {
|
||||
$password = trim( $password_to_add );
|
||||
if ( '' === $password ) {
|
||||
continue;
|
||||
}
|
||||
$password_data = array(
|
||||
'post_id' => $post_id,
|
||||
'created_time' => time(),
|
||||
'campaign_app_type' => PPW_Content_Protection::PASSWORD_GLOBAL_TYPE,
|
||||
'password' => $password,
|
||||
'usage_limit' => null,
|
||||
'expired_date' => null,
|
||||
);
|
||||
|
||||
$ppwp_db->add_new_password( $password_data );
|
||||
}
|
||||
|
||||
$ids = array();
|
||||
foreach ( $raw_password_dbs as $raw_password_db ) {
|
||||
if ( in_array( $raw_password_db->password, $passwords_to_delete ) ) {
|
||||
$ids[] = $raw_password_db->id;
|
||||
}
|
||||
}
|
||||
$ids = array_unique( $ids );
|
||||
$ppwp_db->delete_passwords( $ids, $post_id );
|
||||
} else {
|
||||
foreach ( $passwords as $password ) {
|
||||
$password = trim( $password );
|
||||
if ( '' === $password ) {
|
||||
continue;
|
||||
}
|
||||
$password_data = array(
|
||||
'post_id' => $post_id,
|
||||
'created_time' => time(),
|
||||
'campaign_app_type' => PPW_Content_Protection::PASSWORD_GLOBAL_TYPE,
|
||||
'password' => $password,
|
||||
'usage_limit' => null,
|
||||
'expired_date' => null,
|
||||
);
|
||||
|
||||
$ppwp_db->add_new_password( $password_data );
|
||||
}
|
||||
}
|
||||
|
||||
return new WP_REST_Response(
|
||||
array(
|
||||
'success' => true,
|
||||
),
|
||||
200
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,522 @@
|
||||
<?php
|
||||
/**
|
||||
* The admin-specific functionality of the plugin.
|
||||
*
|
||||
* @link https://www.buildwps.com/
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Prevent_ur_pages
|
||||
* @subpackage Prevent_ur_pages/include
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Defines the Constants
|
||||
*
|
||||
* @package Prevent_ur_pages
|
||||
* @subpackage Prevent_ur_pages/include
|
||||
* @author Bwps <support@bwps.us>
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'PPW_Constants' ) ) {
|
||||
/**
|
||||
* Constants helper class
|
||||
*
|
||||
* Class PPW_Free_Constants
|
||||
*/
|
||||
class PPW_Constants {
|
||||
// Hook.
|
||||
const HOOK_IS_PRO_ACTIVATE = 'ppw_is_pro_activate';
|
||||
|
||||
const HOOK_CUSTOM_STYLE_FORM_ENTIRE_SITE = 'ppw_free_custom_style_form_entire_site';
|
||||
|
||||
const HOOK_MESSAGE_ENTERING_WRONG_PASSWORD = 'ppwp_text_for_entering_wrong_password';
|
||||
|
||||
const HOOK_MESSAGE_PASSWORD_FORM = 'ppwp_customize_password_form_message';
|
||||
|
||||
const HOOK_CUSTOM_PASSWORD_FORM = 'ppwp_customize_password_form';
|
||||
|
||||
const HOOK_CALLBACK_URL = 'ppwp_callback_url';
|
||||
|
||||
const CALL_BACK_URL_PARAM = 'callback_url';
|
||||
|
||||
const HOOK_SHOULD_RENDER_PASSWORD_FORM = 'ppwp_should_render_password_form';
|
||||
|
||||
const HOOK_DEFAULT_TAB = 'ppw_default_tab';
|
||||
|
||||
const HOOK_SITEWIDE_TAB = 'ppw_sitewide_tab';
|
||||
|
||||
const HOOK_PCP_TAB = 'ppw_pcp_tab';
|
||||
|
||||
const HOOK_ADD_NEW_TAB = 'ppw_add_new_tab';
|
||||
|
||||
const HOOK_ADD_NEW_SITEWIDE_SUBMENU = 'ppw_sitewide_submenu_add_new_tab';
|
||||
|
||||
const HOOK_ADD_NEW_PCP_SUBMENU = 'ppw_pcp_submenu_add_new_tab';
|
||||
|
||||
const HOOK_RENDER_CONTENT_FOR_TAB = 'ppw_render_content_';
|
||||
|
||||
const HOOK_CUSTOM_TAB = 'ppw_custom_tab';
|
||||
|
||||
const HOOK_CUSTOM_SITEWIDE_TAB = 'ppw_custom_sitewide_tab';
|
||||
|
||||
const HOOK_CUSTOM_PCP_TAB = 'ppw_custom_pcp_tab';
|
||||
|
||||
const HOOK_RENDER_CONTENT_FOR_SITEWIDE_TAB = 'ppw_render_sitewide_content_';
|
||||
|
||||
const HOOK_RENDER_CONTENT_FOR_PCP_TAB = 'ppw_render_pcp_content_';
|
||||
|
||||
const HOOK_COOKIE_EXPIRED = 'post_password_expires';
|
||||
|
||||
const HOOK_CHECK_PASSWORD_BEFORE_RENDER_CONTENT = 'ppw_check_password_before_render_content';
|
||||
|
||||
const HOOK_FUNCTION_HANDLE_META_BOX = 'ppw_function_handle_meta_box';
|
||||
|
||||
const HOOK_META_BOX_POSITION = 'ppw_meta_box_position';
|
||||
|
||||
const HOOK_CHECK_PASSWORD_IS_VALID = 'ppw_check_password_is_valid';
|
||||
|
||||
const HOOK_BEFORE_RENDER_FORM_ENTIRE_SITE = 'ppw_before_render_form_entire_site';
|
||||
|
||||
const HOOK_HIDE_DEFAULT_PW_WP_POSITION = 'ppw_hide_default_pw_wp_position';
|
||||
|
||||
const HOOK_PLUGIN_INFO = 'ppw_plugin_info';
|
||||
|
||||
const HOOK_CUSTOM_HEADER_FORM_ENTIRE_SITE = 'ppw_custom_header_form_entire_site';
|
||||
|
||||
const HOOK_CUSTOM_FOOTER_FORM_ENTIRE_SITE = 'ppw_custom_footer_form_entire_site';
|
||||
|
||||
const HOOK_CUSTOM_TEXT_FEATURE_REMOVE_DATA = 'ppw_custom_text_feature_remove_data';
|
||||
|
||||
const HOOK_POST_TYPES = 'ppw_post_types';
|
||||
|
||||
const HOOK_MIGRATE_COMPLETE_MESSAGE = 'ppw_complete_message';
|
||||
|
||||
const HOOK_PARAM_PASSWORD_SUCCESS = 'ppw_custom_param';
|
||||
|
||||
const HOOK_SHORT_CODE_ATTRS = 'ppw_short_code_attributes';
|
||||
|
||||
const HOOK_SUPPORTED_WHITELIST_ROLES = 'ppw_supported_white_list_roles';
|
||||
|
||||
const HOOK_SUPPORTED_POST_TYPES = 'ppw_supported_post_types';
|
||||
|
||||
const HOOK_SHORT_CODE_TEMPLATE = 'ppw_short_code_template';
|
||||
|
||||
const HOOK_RESTRICT_CONTENT_ERROR_MESSAGE = 'ppw_restrict_content_custom_error_message';
|
||||
|
||||
const HOOK_RESTRICT_CONTENT_BEFORE_CHECK_PWD = 'ppw_restrict_content_before_check_pw';
|
||||
|
||||
const HOOK_RESTRICT_CONTENT_AFTER_VALID_PWD = 'ppw_restrict_content_after_valid_pw';
|
||||
|
||||
const HOOK_SHORT_CODE_WHITELISTED_ROLES = 'ppw_restrict_content_whitelisted_roles';
|
||||
|
||||
const HOOK_SHORT_CODE_ERROR_MESSAGE = 'ppw_restrict_content_error_message';
|
||||
|
||||
const HOOK_SHORTCODE_NOT_SUPPORT_TYPE_ERROR_MESSAGE = 'ppw_restrict_content_not_support_post_type_error_message';
|
||||
|
||||
const HOOK_SHORT_CODE_BEFORE_CHECK_PASSWORD = 'ppw_restrict_content_before_check_password';
|
||||
|
||||
const HOOK_SHORT_CODE_AFTER_CHECK_PASSWORD = 'ppw_restrict_content_before_check_password';
|
||||
|
||||
const HOOK_SHORT_CODE_VALID_POST_DATA = 'ppw_restrict_content_valid_post_data';
|
||||
|
||||
const HOOK_HANDLE_BEFORE_RENDER_WOO_PRODUCT = 'ppw_handle_before_render_woo_product';
|
||||
|
||||
const HOOK_SHORTCODE_ATTRIBUTES_VALIDATION = 'ppw_shortcode_attributes_validation';
|
||||
|
||||
const HOOK_SHORTCODE_PASSWORDS = 'ppw_shortcode_passwords';
|
||||
|
||||
const HOOK_SHORTCODE_RENDER_CONTENT = 'ppw_shortcode_render_content';
|
||||
|
||||
const HOOK_SHORTCODE_CONTENT_SOURCE = 'ppw_content_shortcode_source';
|
||||
|
||||
const HOOK_SHORTCODE_SETTINGS_EXTENDS = 'ppw_shortcode_settings_extend';
|
||||
|
||||
const HOOK_MASTER_PASSWORDS_VALID_POST_TYPES = 'ppw_master_passwords_valid_post_types';
|
||||
|
||||
const HOOK_SHORTCODE_BEAVER_BUILDER_FIELDS = 'ppw_shortcode_beaver_builder_fields';
|
||||
|
||||
const HOOK_SHORTCODE_BEAVER_BUILDER_GENERAL_FIELDS = 'ppw_shortcode_beaver_builder_general_fields';
|
||||
|
||||
const HOOK_SHORTCODE_BEAVER_BUILDER_INSTRUCTION_FIELDS = 'ppw_shortcode_beaver_builder_instruction_fields';
|
||||
|
||||
const HOOK_SHORTCODE_BEAVER_BUILDER_ATTRIBUTES = 'ppw_shortcode_beaver_builder_attributes';
|
||||
|
||||
const HOOK_SHORTCODE_ELEMENTOR_CONTROLS = 'ppw_shortcode_elementor_controls';
|
||||
|
||||
const HOOK_SHORTCODE_ELEMENTOR_ATTRIBUTES = 'ppw_shortcode_elementor_attributes';
|
||||
|
||||
const HOOK_SHORTCODE_ELEMENTOR_CONTENT = 'ppw_shortcode_elementor_content';
|
||||
|
||||
const HOOK_SHORTCODE_ELEMENTOR_PREVIEW_CONTENT = 'ppw_shortcode_elementor_preview_content';
|
||||
|
||||
const HOOK_SHORTCODE_BEFORE_RENDER_PASSWORD_FORM = 'ppw_shortcode_before_render_password_form';
|
||||
|
||||
const HOOK_SIDEBAR_SHORTCODE = 'ppw_sidebar_shortcode';
|
||||
|
||||
const HOOK_CHECK_CONTENT_IS_PROTECTED_BY_PRO = 'ppw_check_content_is_protected_by_pro';
|
||||
|
||||
const HOOK_CUSTOM_OPTION_HIDE_PROTECT_CONTENT = 'ppw_custom_option_hide_protect_content';
|
||||
|
||||
const HOOK_CUSTOM_POST_TYPE_HIDE_PROTECTED_POST = 'ppw_custom_post_type_for_hide_protected_post';
|
||||
|
||||
const HOOK_CUSTOM_POST_TYPE_RECENT_POST = 'ppw_custom_post_type_for_recent_post';
|
||||
|
||||
const HOOK_CUSTOM_POST_TYPE_NEXT_AND_PREVIOUS = 'ppw_custom_post_type_for_next_and_previous';
|
||||
|
||||
const HOOK_CUSTOM_POST_ID_HIDE_PROTECTED_POST = 'ppw_custom_post_id_for_hide_protected_post';
|
||||
|
||||
const HOOK_CUSTOM_DEFAULT_OPTIONS_HIDE_PROTECTED_POST = 'ppw_custom_default_options_for_hide_protected_post';
|
||||
|
||||
const HOOK_CUSTOM_POSITIONS_HIDE_PROTECTED_POST = 'ppw_custom_positions_for_hide_protected_post';
|
||||
|
||||
const HOOK_SHORTCODE_ALLOW_BYPASS_VALID_POST_TYPE = 'ppw_shortcode_allow_bypass_valid_post_type';
|
||||
|
||||
const HOOK_ADVANCED_TAB_LOAD_ASSETS = 'ppw_misc_tab_load_assets';
|
||||
|
||||
const HOOK_ADVANCED_VALID_INPUT_DATA = 'ppw_misc_valid_input_data';
|
||||
// End hook.
|
||||
|
||||
// Short code attribute.
|
||||
const SHORT_CODE_FORM_HEADLINE = '[PPWP_FORM_HEADLINE]';
|
||||
|
||||
const SHORT_CODE_FORM_INSTRUCT = '[PPWP_FORM_INSTRUCTIONS]';
|
||||
|
||||
const SHORT_CODE_FORM_PLACEHOLDER = '[PPW_PLACEHOLDER]';
|
||||
|
||||
const SHORT_CODE_FORM_AUTH = '[PPW_AUTH]';
|
||||
|
||||
const SHORT_CODE_FORM_CURRENT_URL = '[PPW_CURRENT_URL]';
|
||||
|
||||
const SHORT_CODE_FORM_ERROR_MESSAGE = '[PPW_ERROR_MESSAGE]';
|
||||
|
||||
const SHORT_CODE_BUTTON = '[PPW_BUTTON_LABEL]';
|
||||
|
||||
const SHORT_CODE_FORM_ID = '[PPW_FORM_ID]';
|
||||
|
||||
const SHORT_CODE_FORM_CLASS = '[PPW_FORM_CLASS]';
|
||||
|
||||
const SHORT_CODE_PASSWORD_LABEL = '[PPWP_FORM_PASSWORD_LABEL]';
|
||||
|
||||
const SHORTCODE_ABOVE_PASSWORD_INPUT = '[PPWP_FORM_ABOVE_PASSWORD_INPUT]';
|
||||
|
||||
const SHORTCODE_BELOW_PASSWORD_INPUT = '[PPWP_FORM_BELOW_PASSWORD_INPUT]';
|
||||
|
||||
const SHORTCODE_DESC_ABOVE_BTN = '[SHORTCODE_DESC_ABOVE_BTN]';
|
||||
|
||||
const SHORTCODE_DESC_BELOW_FORM = '[SHORTCODE_DESC_BELOW_FORM]';
|
||||
// End short code attribute.
|
||||
|
||||
// Default.
|
||||
const DEFAULT_SUBMIT_LABEL = 'Enter';
|
||||
|
||||
const DEFAULT_PASSWORD_LABEL = 'Password:';
|
||||
|
||||
const DEFAULT_HEADLINE_TEXT = '';
|
||||
|
||||
const DEFAULT_PLACEHOLDER = '';
|
||||
|
||||
const DEFAULT_IS_SHOW_PASSWORD = 0;
|
||||
|
||||
const DEFAULT_FORM_BACKGROUND_COLOR = '';
|
||||
|
||||
const DEFAULT_FORM_PADDING = '';
|
||||
|
||||
const DEFAULT_FORM_MARGIN = '';
|
||||
|
||||
const DEFAULT_FORM_BORDER_RADIUS = '';
|
||||
|
||||
const DEFAULT_HEADLINE_FONT_SIZE = '';
|
||||
|
||||
const DEFAULT_HEADLINE_FONT_WEIGHT = '';
|
||||
|
||||
const DEFAULT_HEADLINE_FONT_COLOR = '';
|
||||
|
||||
const DEFAULT_TEXT_FONT_SIZE = '';
|
||||
|
||||
const DEFAULT_TEXT_FONT_WEIGHT = '';
|
||||
|
||||
const DEFAULT_TEXT_FONT_COLOR = '';
|
||||
|
||||
const DEFAULT_ERROR_TEXT_FONT_SIZE = '';
|
||||
|
||||
const DEFAULT_ERROR_TEXT_FONT_WEIGHT = '';
|
||||
|
||||
const DEFAULT_ERROR_TEXT_FONT_COLOR = '#dc3232';
|
||||
|
||||
const DEFAULT_ERROR_TEXT_BACKGROUND_COLOR = '';
|
||||
|
||||
const DEFAULT_BUTTON_TEXT_FONT_COLOR = '';
|
||||
|
||||
const DEFAULT_BUTTON_BACKGROUND_COLOR = '';
|
||||
|
||||
const DEFAULT_BUTTON_TEXT_HOVER_COLOR = '';
|
||||
|
||||
const DEFAULT_BUTTON_BACKGROUND_HOVER_COLOR = '';
|
||||
|
||||
const DEFAULT_SHOW_PASSWORD_TEXT = 'Show password';
|
||||
|
||||
const DEFAULT_SHOW_PASSWORD_TEXT_SIZE = '';
|
||||
|
||||
const DEFAULT_PASSWORD_LABEL_FONT_COLOR = '';
|
||||
// End default.
|
||||
|
||||
// Message.
|
||||
const DEFAULT_FORM_MESSAGE = 'This content is password protected. To view it please enter your password below:';
|
||||
|
||||
const DEFAULT_SHORTCODE_DESC_ABOVE_PWD_BTN = '';
|
||||
|
||||
const DEFAULT_SHORTCODE_DESC_BELOW_PWD_FORM = '';
|
||||
|
||||
const DEFAULT_WRONG_PASSWORD_MESSAGE = 'Please enter the correct password!';
|
||||
|
||||
const DEFAULT_ERROR_RECAPTCHA_MESSAGE = 'Google reCAPTCHA verification failed, please try again later.';
|
||||
|
||||
const BAD_REQUEST_MESSAGE = 'Our server cannot understand the data request!';
|
||||
|
||||
const EMPTY_PASSWORD = 'Please fill out empty fields.';
|
||||
|
||||
const DUPLICATE_PASSWORD = 'You can\'t create duplicate password. Please try again.';
|
||||
|
||||
const SPACE_PASSWORD = 'Spaces not accepted in password. Please remove them and try again.';
|
||||
// End message.
|
||||
|
||||
// Modules.
|
||||
const MENU_NAME = 'wp_protect_password_options';
|
||||
|
||||
const SITEWIDE_PAGE_PREFIX = 'ppwp-sitewide';
|
||||
|
||||
const EXTERNAL_SERVICES_PREFIX = 'ppwp-integrations';
|
||||
|
||||
const PCP_PAGE_PREFIX = 'ppwp-partial-protection';
|
||||
|
||||
const META_BOX_MODULE = 'meta-box';
|
||||
|
||||
const ENTIRE_SITE_MODULE = 'entire-site';
|
||||
|
||||
const GENERAL_SETTINGS_MODULE = 'general';
|
||||
|
||||
const EXTERNAL_SETTINGS_MODULE = 'external';
|
||||
|
||||
const EXTERNAL_CONFIGURATION_MODULE = 'external-configuration';
|
||||
|
||||
const MISC_SETTINGS_MODULE = 'misc';
|
||||
|
||||
const TROUBLESHOOT_SETTINGS_MODULE = 'troubleshooting';
|
||||
|
||||
const SHORTCODES_SETTINGS_MODULE = 'shortcodes';
|
||||
// End modules.
|
||||
|
||||
const COOKIE_NAME = 'wp-postpass-role_';
|
||||
|
||||
const ENTIRE_SITE_FORM_NONCE = 'ppw_entire_site_form_nonce';
|
||||
|
||||
const GENERAL_FORM_NONCE = 'ppw_general_form_nonce';
|
||||
|
||||
const PCP_FORM_NONCE = 'ppw_pcp_nonce';
|
||||
|
||||
const ROW_ACTION_NONCE = 'ppw_row_action_nonce';
|
||||
|
||||
const ENTIRE_SITE_OPTIONS = 'wp_protect_password_set_password_options';
|
||||
|
||||
const GENERAL_OPTIONS = 'wp_protect_password_setting_options';
|
||||
|
||||
const MISC_OPTIONS = 'wp_protect_password_misc_options';
|
||||
|
||||
const SHORTCODE_OPTIONS = 'wp_protect_password_shortcode_options';
|
||||
|
||||
const EXTERNAL_OPTIONS = 'wp_protect_password_external_options';
|
||||
|
||||
const POST_PROTECTION_ROLES = 'post_protection_roles';
|
||||
|
||||
const ENTIRE_SITE_COOKIE_NAME = 'pda_protect_password';
|
||||
|
||||
const GLOBAL_PASSWORDS = 'wp_protect_password_multiple_passwords';
|
||||
|
||||
const COOKIE_EXPIRED = 'wpp_password_cookie_expired';
|
||||
|
||||
const REMOVE_DATA = 'wpp_remove_data';
|
||||
|
||||
const USE_CUSTOM_FORM_ACTION = 'wpp_use_custom_form_action';
|
||||
|
||||
const NO_RELOAD_PAGE = 'wpp_no_reload_page';
|
||||
|
||||
const USE_SHORTCODE_PAGE_BUILDER = 'wpp_use_shortcode_page_builder';
|
||||
|
||||
const USING_RECAPTCHA = 'wpp_use_recaptcha';
|
||||
|
||||
const RECAPTCHA_TYPE = 'wpp_recaptcha_type';
|
||||
|
||||
const RECAPTCHA_PASSWORD_TYPES = 'wpp_recaptcha_password_types';
|
||||
|
||||
const RECAPTCHA_API_KEY = 'wpp_recaptcha_api_key';
|
||||
|
||||
const RECAPTCHA_V2_CHECKBOX_API_KEY = 'wpp_recaptcha_v2_checkbox_api_key';
|
||||
|
||||
const RECAPTCHA_API_SECRET = 'wpp_recaptcha_api_secret';
|
||||
|
||||
const RECAPTCHA_V2_CHECKBOX_API_SECRET = 'wpp_recaptcha_v2_checkbox_api_secret';
|
||||
|
||||
const RECAPTCHA_SCORE = 'wpp_recaptcha_score';
|
||||
|
||||
const PROTECT_EXCERPT = 'wpp_protect_excerpt';
|
||||
|
||||
const MAX_COOKIE_EXPIRED = 8760;
|
||||
|
||||
const MIN_COOKIE_EXPIRED = 0;
|
||||
|
||||
const DOMAIN = 'password-protect-page';
|
||||
|
||||
const WRONG_PASSWORD_PARAM = 'ppwp_enter_wrong_password';
|
||||
|
||||
const PASSWORD_PARAM_NAME = 'ppwp';
|
||||
|
||||
const PASSWORD_PARAM_VALUE = '1';
|
||||
|
||||
const IS_PROTECT_ENTIRE_SITE = 'ppwp_apply_password_for_entire_site';
|
||||
|
||||
const PASSWORD_ENTIRE_SITE = 'password_for_website';
|
||||
|
||||
const SET_NEW_PASSWORD_ENTIRE_SITE = 'ppwp_set_new_password_for_entire_site';
|
||||
|
||||
const META_BOX_NONCE = 'ppw_meta_box_nonce';
|
||||
|
||||
const SUBSCRIBE_FORM_NONCE = 'ppw_subscribe_form_nonce';
|
||||
|
||||
const USER_SUBSCRIBE = 'ppw_free_subscribe';
|
||||
|
||||
const MIGRATED_DEFAULT_PW = 'migrated_default_pw';
|
||||
|
||||
const MIGRATED_FREE_FLAG = 'migrated_free';
|
||||
|
||||
const PRO_DIRECTORY = 'wp_protect_password/wp-protect-password.php';
|
||||
|
||||
const PRO_ROOT_DIR = 'wp_protect_password';
|
||||
|
||||
const DEV_PRO_DIRECTORY = 'password-protect-page-pro/wp-protect-password.php';
|
||||
|
||||
const DEV_PRO_ROOT_DIR = 'password-protect-page-pro';
|
||||
|
||||
const PPW_HOOK_SHORT_CODE_NAME = 'ppwp';
|
||||
|
||||
const PPW_ERROR_MESSAGE_COLOR = '#dc3232';
|
||||
|
||||
const WP_POST_PASS = 'wp-postpass_';
|
||||
|
||||
const CUSTOM_POST_CLASS = 'ppwp-short-code-post';
|
||||
|
||||
const CUSTOM_TABLE_COLUMN_NAME = 'ppw_password_protection';
|
||||
|
||||
const CUSTOM_TABLE_COLUMN_TITLE = 'Password Protection';
|
||||
|
||||
const DEFAULT_SHORTCODE_CLASS_NAME = 'ppw-restricted-content';
|
||||
|
||||
const DEFAULT_SHORTCODE_HEADLINE = 'Restricted Content';
|
||||
|
||||
const DEFAULT_SHORTCODE_DESCRIPTION = 'To view this protected content, enter the password below:';
|
||||
|
||||
const DEFAULT_SHORTCODE_BUTTON = 'Enter';
|
||||
|
||||
const DEFAULT_SHORTCODE_LABEL = 'Password:';
|
||||
|
||||
const DEFAULT_SHORTCODE_ERROR_MSG = 'Please enter the correct password!';
|
||||
|
||||
const DEFAULT_SHORTCODE_LOADING = 'Loading...';
|
||||
|
||||
const DEFAULT_SHORTCODE_SHOW_PASSWORD = false;
|
||||
|
||||
const DEFAULT_SHORTCODE_SHOW_PASSWORD_TEXT = 'Show password';
|
||||
|
||||
const TBL_NAME = 'pda_passwords';
|
||||
|
||||
const TBL_VERSION = 'pda-pwd-tbl-version';
|
||||
|
||||
const DB_DATA_COLUMN_TABLE = array(
|
||||
array(
|
||||
'old_version' => '1.0',
|
||||
'new_version' => '1.1',
|
||||
'value' => 'hits_count mediumint(9) NOT NULL',
|
||||
),
|
||||
array(
|
||||
'old_version' => '1.1',
|
||||
'new_version' => '1.2',
|
||||
'value' => 'is_default tinyint(1) DEFAULT 0',
|
||||
),
|
||||
array(
|
||||
'old_version' => '1.2',
|
||||
'new_version' => '1.3',
|
||||
'value' => 'expired_date BIGINT DEFAULT NULL',
|
||||
),
|
||||
array(
|
||||
'old_version' => '1.3',
|
||||
'new_version' => '1.4',
|
||||
'value' => 'usage_limit mediumint(9)',
|
||||
),
|
||||
);
|
||||
|
||||
const DB_UPDATE_COLUMN_TABLE = array(
|
||||
array(
|
||||
'old_version' => '1.4',
|
||||
'new_version' => '1.5',
|
||||
'value' => "campaign_app_type campaign_app_type text DEFAULT '' NULL",
|
||||
),
|
||||
array(
|
||||
'old_version' => '1.5',
|
||||
'new_version' => '1.6',
|
||||
'value' => "password password varchar(255) DEFAULT '' NULL",
|
||||
),
|
||||
);
|
||||
|
||||
const PPW_MASTER_GLOBAL = 'master_global';
|
||||
|
||||
const PPW_MASTER_ROLE = 'master_role_';
|
||||
|
||||
const MASTER_COOKIE_NAME = 'ppw_master-';
|
||||
|
||||
// Const for feature "Hide Protected Content".
|
||||
|
||||
const DEFAULT_POST_TYPE = array( 'post', 'page' );
|
||||
|
||||
const HIDE_PROTECTED = 'ppw_hide_protected_';
|
||||
|
||||
const HIDE_SELECTED = 'ppw_hide_selected_';
|
||||
|
||||
const FRONT_PAGE = 'ppw_front_page';
|
||||
|
||||
const CATEGORY_PAGE = 'ppw_category_page';
|
||||
|
||||
const TAG_PAGE = 'ppw_tag_page';
|
||||
|
||||
const AUTHOR_PAGE = 'ppw_author_page';
|
||||
|
||||
const ARCHIVES_PAGE = 'ppw_archives_page';
|
||||
|
||||
const NEXT_PREVIOUS = 'ppw_next_previous';
|
||||
|
||||
const RECENT_POST = 'ppw_recent_post';
|
||||
|
||||
const SEARCH_RESULTS = 'ppw_search_results';
|
||||
|
||||
const FEEDS = 'ppw_feeds';
|
||||
|
||||
const EVERYWHERE_PAGE = 'ppw_everywhere_pages';
|
||||
|
||||
const XML_YOAST_SEO_SITEMAPS = 'ppw_xml_yoast_seo_sitemaps';
|
||||
// End const for feature "Hide Protected Content".
|
||||
|
||||
const PROTECTION_STATUS = array(
|
||||
'protect' => 1,
|
||||
'unprotect' => 0,
|
||||
);
|
||||
|
||||
const PROTECT_LABEL = 'Protect';
|
||||
|
||||
const UNPROTECT_LABEL = 'Unprotect';
|
||||
|
||||
const CONTEXT_PASSWORD_FORM = 'PPF';
|
||||
|
||||
const CONTEXT_PCP_PASSWORD_FORM = 'PCP';
|
||||
|
||||
const CONTEXT_SITEWIDE_PASSWORD_FORM = 'SWP Lite';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,563 @@
|
||||
<?php
|
||||
/**
|
||||
* Class PPW_Repository_Passwords
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'PPW_Repository_Passwords' ) ) {
|
||||
/**
|
||||
* DB class to create table and manage version
|
||||
* Class PPW_Pro_DB
|
||||
*/
|
||||
class PPW_Repository_Passwords {
|
||||
/**
|
||||
* Table version
|
||||
* @var string
|
||||
*/
|
||||
private $tbl_version;
|
||||
/**
|
||||
* Table name
|
||||
* @var string
|
||||
*/
|
||||
private $tbl_name;
|
||||
|
||||
/**
|
||||
* @var object
|
||||
*/
|
||||
private $wpdb;
|
||||
|
||||
/**
|
||||
* Instance of PPW_Pro_Shortcode class.
|
||||
*
|
||||
* @var PPW_Repository_Passwords
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* PPW_Pro_DB constructor.
|
||||
*
|
||||
* @param $prefix
|
||||
*/
|
||||
public function __construct( $prefix = false ) {
|
||||
global $wpdb;
|
||||
$this->wpdb = $wpdb;
|
||||
$this->tbl_version = $this->get_table_version();
|
||||
$this->tbl_name = ! $prefix ? $this->wpdb->prefix . PPW_Constants::TBL_NAME : $prefix . PPW_Constants::TBL_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short code instance
|
||||
*
|
||||
* @return PPW_Repository_Passwords
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( is_null( self::$instance ) ) {
|
||||
// Use static instead of self due to the inheritance later.
|
||||
// For example: ChildSC extends this class, when we call get_instance
|
||||
// it will return the object of child class. On the other hand, self function
|
||||
// will return the object of base class.
|
||||
self::$instance = new static();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install table
|
||||
*/
|
||||
public function install() {
|
||||
// TODO: Check highest version to create table.
|
||||
$this->init_tbl();
|
||||
|
||||
// Add new column.
|
||||
foreach ( PPW_Constants::DB_DATA_COLUMN_TABLE as $data ) {
|
||||
$this->add_new_column( $data['old_version'], $data['new_version'], $data['value'] );
|
||||
}
|
||||
|
||||
// Update column.
|
||||
foreach ( PPW_Constants::DB_UPDATE_COLUMN_TABLE as $dt ) {
|
||||
$this->update_table( $dt['old_version'], $dt['new_version'], $dt['value'] );
|
||||
}
|
||||
|
||||
// TODO: Add column for pro version.
|
||||
$this->update_label_and_post_types_column();
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall table
|
||||
*/
|
||||
public function uninstall() {
|
||||
$this->wpdb->query( "DROP TABLE IF EXISTS $this->tbl_name" ); // phpcs:ignore -- We do not need to prepare because don't have any param to pass.
|
||||
}
|
||||
|
||||
/**
|
||||
* Init table
|
||||
*/
|
||||
private function init_tbl() {
|
||||
if ( $this->is_table_does_not_exist() ) {
|
||||
$charset_collate = $this->wpdb->get_charset_collate();
|
||||
$sql = "CREATE TABLE $this->tbl_name (
|
||||
id mediumint(9) NOT NULL AUTO_INCREMENT,
|
||||
post_id mediumint(9) NOT NULL,
|
||||
contact_id mediumint(9) NULL,
|
||||
campaign_app_type varchar(50) DEFAULT '' NULL,
|
||||
password varchar(30) NOT NULL,
|
||||
is_activated tinyint(1) DEFAULT 1,
|
||||
created_time BIGINT DEFAULT NULL,
|
||||
expired_time BIGINT DEFAULT NULL,
|
||||
UNIQUE KEY id(id)
|
||||
) $charset_collate;";
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
dbDelta( $sql );
|
||||
|
||||
// Init setting when installing plugin firstly.
|
||||
update_option( PPW_Constants::MISC_OPTIONS, wp_json_encode( array( 'wpp_use_custom_form_action' => 'true' ) ), 'no' );
|
||||
|
||||
$this->tbl_version = "1.0";
|
||||
$this->update_table_version( $this->tbl_version );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new column for table
|
||||
*
|
||||
* @param $old_version
|
||||
* @param $new_version
|
||||
* @param $value
|
||||
*/
|
||||
private function add_new_column( $old_version, $new_version, $value ) {
|
||||
if ( $this->tbl_version === $old_version ) {
|
||||
if ( is_null( $this->check_column_exist( $value ) ) ) {
|
||||
$charset_collate = $this->wpdb->get_charset_collate();
|
||||
$sql = "CREATE TABLE $this->tbl_name ( $value ) $charset_collate;";
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
dbDelta( $sql );
|
||||
}
|
||||
$this->tbl_version = $new_version;
|
||||
$this->update_table_version( $this->tbl_version );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update value for column in table
|
||||
*
|
||||
* @param $old_version
|
||||
* @param $new_version
|
||||
* @param $value
|
||||
*/
|
||||
private function update_table( $old_version, $new_version, $value ) {
|
||||
if ( $this->tbl_version === $old_version ) {
|
||||
$sql = "ALTER TABLE $this->tbl_name CHANGE $value";
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
$this->wpdb->query( $sql ); // phpcs:ignore -- We don't need to prepare this one.
|
||||
|
||||
$this->tbl_version = $new_version;
|
||||
$this->update_table_version( $this->tbl_version );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check table is exist
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_table_does_not_exist() {
|
||||
$preparation = $this->wpdb->prepare( 'SHOW TABLES LIKE %s', $this->tbl_name );
|
||||
return $this->wpdb->get_var( $preparation ) != $this->tbl_name; // phpcs:ignore -- we already prepared above, but there are no data to prepare
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plugin table's version
|
||||
*/
|
||||
private function get_table_version() {
|
||||
$version = get_option( PPW_Constants::TBL_VERSION, false );
|
||||
|
||||
return ! $version ? '1.0' : $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update table version
|
||||
*
|
||||
* @param $version
|
||||
*/
|
||||
private function update_table_version( $version ) {
|
||||
update_option( PPW_Constants::TBL_VERSION, $version );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get password info by password and post id
|
||||
*
|
||||
* @param string $password The password.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_master_password_info_by_password( $password ) {
|
||||
$like_master_param = 'master_';
|
||||
$query_string = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE BINARY password = %s and campaign_app_type LIKE %s and post_id = 0 and is_activated = 1 and (expired_date is NULL OR expired_date > UNIX_TIMESTAMP()) and (usage_limit is NULL OR hits_count < usage_limit)", $password, $this->wpdb->esc_like( $like_master_param ) . '%' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
|
||||
|
||||
return $this->wpdb->get_row( $query_string ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get master password which activating.
|
||||
*
|
||||
* @return array|object|null Database query results.
|
||||
*/
|
||||
public function get_activate_master_passwords_info() {
|
||||
$like_master_param = 'master_';
|
||||
$query_string = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE post_id = 0 AND campaign_app_type LIKE %s and is_activated = 1", $this->wpdb->esc_like( $like_master_param ) . '%' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder.
|
||||
|
||||
return $this->wpdb->get_results( $query_string ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
/**
|
||||
* Get master password which in database.
|
||||
*
|
||||
* @return array|object|null Database query results.
|
||||
*/
|
||||
public function get_master_passwords_info() {
|
||||
$like_master_param = 'master_';
|
||||
$query_string = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE post_id = 0 AND campaign_app_type LIKE %s", $this->wpdb->esc_like( $like_master_param ) . '%' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
|
||||
|
||||
return $this->wpdb->get_results( $query_string ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a row in table by id.
|
||||
*
|
||||
* @param array $data Data to add.
|
||||
*
|
||||
* @return int|false The number of rows updated, or false on error.
|
||||
*/
|
||||
public function add_new_password( $data ) {
|
||||
$is_added = $this->wpdb->insert( $this->tbl_name, $data );
|
||||
if ( $is_added ) {
|
||||
return $this->wpdb->insert_id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function delete_passwords( $ids, $post_id ) {
|
||||
$ids = implode( ',', array_map( 'absint', $ids ) );
|
||||
$post_id = absint( $post_id );
|
||||
$query_string = $this->wpdb->prepare( "DELETE FROM {$this->tbl_name} WHERE id IN(%1s) AND post_id = %d", $ids, $post_id ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- We don't want to set table name as placeholder and put the $ids in quotes.
|
||||
$this->wpdb->query( $query_string ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
/**
|
||||
* Find password by post ID.
|
||||
*
|
||||
* @param string $password Password.
|
||||
*
|
||||
* @return array|object|void|null Database query result in format specified by $output or null on failure
|
||||
*/
|
||||
public function find_by_master_password( $password ) {
|
||||
$like_master_param = 'master_';
|
||||
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE BINARY password = %s AND post_id = 0 AND campaign_app_type LIKE %s", $password, $this->wpdb->esc_like( $like_master_param ) . '%' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
|
||||
|
||||
return $this->wpdb->get_row( $sql ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
/**
|
||||
* Find shared category password.
|
||||
*
|
||||
* @param string $password Password.
|
||||
*
|
||||
* @return array|object|void|null Database query result in format specified by $output or null on failure
|
||||
*/
|
||||
public function find_by_shared_category_password( $password ) {
|
||||
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE BINARY password = %s AND post_id = 0 AND campaign_app_type = %s", $password, PPW_Category_Service::SHARED_CATEGORY_TYPE ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
|
||||
|
||||
return $this->wpdb->get_row( $sql ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all shared categories password.
|
||||
*
|
||||
* @return array|object|void|null Database query result in format specified by $output or null on failure
|
||||
*/
|
||||
public function get_all_shared_categories_password() {
|
||||
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE post_id = 0 AND campaign_app_type = %s", PPW_Category_Service::SHARED_CATEGORY_TYPE ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
|
||||
|
||||
return $this->wpdb->get_results( $sql ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
public function get_passwords_with_type_and_post_id( $type, $post_id, $column = '*' ) {
|
||||
$sql = $this->wpdb->prepare( "SELECT %1s FROM {$this->tbl_name} WHERE post_id = %d AND campaign_app_type = %s", $column, $post_id, $type ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- We don't want to set table name as placeholder, and put $column in quotes.
|
||||
|
||||
return $this->wpdb->get_results( $sql ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
/***
|
||||
* Get all custom categories's password
|
||||
* @param $taxonomy_type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_all_custom_categories_password( $taxonomy_type ) {
|
||||
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE post_id = 0 AND campaign_app_type = %s", $taxonomy_type ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
|
||||
|
||||
return $this->wpdb->get_results( $sql ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
/***
|
||||
* Check password with custom category type.
|
||||
*
|
||||
* @param $password
|
||||
* @param $taxonomy
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find_by_shared_custom_category_password( $password, $taxonomy_type ) {
|
||||
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE BINARY password = %s AND post_id = 0 AND campaign_app_type = %s", $password, $taxonomy_type ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
|
||||
|
||||
return $this->wpdb->get_row( $sql ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shared category password by password ID.
|
||||
*
|
||||
* @param int $password_id Password ID.
|
||||
*
|
||||
* @return array|object|void|null Database query result in format specified by $output or null on failure
|
||||
*/
|
||||
public function get_shared_category_password( $password_id ) {
|
||||
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE BINARY id = %d AND campaign_app_type = %s", $password_id, PPW_Category_Service::SHARED_CATEGORY_TYPE ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
|
||||
|
||||
return $this->wpdb->get_row( $sql ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shared category password by password ID.
|
||||
*
|
||||
* @param int $password_id Password ID.
|
||||
*
|
||||
* @return array|object|void|null Database query result in format specified by $output or null on failure
|
||||
*/
|
||||
public function get_shared_custom_category_password( $password_id, $taxonomy ) {
|
||||
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->tbl_name} WHERE id = %d AND campaign_app_type = %s", $password_id, $taxonomy ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
|
||||
|
||||
return $this->wpdb->get_row( $sql ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a row in table by id.
|
||||
*
|
||||
* @param int $id ID.
|
||||
*
|
||||
* @return int|false The number of rows updated, or false on error.
|
||||
*/
|
||||
public function delete( $id ) {
|
||||
return $this->wpdb->delete(
|
||||
$this->tbl_name,
|
||||
array(
|
||||
'id' => absint( $id ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a row in table by id.
|
||||
*
|
||||
* @param int $id ID.
|
||||
* @param array $data Data to update.
|
||||
*
|
||||
* @return int|false The number of rows updated, or false on error.
|
||||
*/
|
||||
public function update_password( $id, $data ) {
|
||||
return $this->wpdb->update(
|
||||
$this->tbl_name,
|
||||
$data,
|
||||
array(
|
||||
'id' => absint( $id ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update label and post types column.
|
||||
*/
|
||||
public function update_label_and_post_types_column() {
|
||||
$this->add_new_column( '1.6', '1.7', 'label TINYTEXT' );
|
||||
$this->add_new_column( '1.7', '1.8', 'post_types varchar(255)' );
|
||||
$this->add_new_column( '1.8', '1.9', 'protection_types varchar(50)' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check column exist in database.
|
||||
*
|
||||
* @param string $value Value to add new column.
|
||||
*
|
||||
* @return string|null|false Database query result (as string), or null on failure
|
||||
* @since 1.4.0 Init function.
|
||||
*/
|
||||
private function check_column_exist( $value ) {
|
||||
if ( empty( $value ) ) {
|
||||
return false;
|
||||
}
|
||||
$value_patterns = explode( ' ', $value );
|
||||
$field_name = $value_patterns[0];
|
||||
$query = $this->wpdb->prepare( "SHOW COLUMNS FROM {$this->tbl_name} LIKE %s", $this->wpdb->esc_like( $field_name ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
|
||||
|
||||
return $this->wpdb->get_var( $query ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all backup post password.
|
||||
*
|
||||
* @return array|object|void|null Database query result in format specified by $output or null on failure
|
||||
*/
|
||||
public function get_wp_post_passwords() {
|
||||
$sql = $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->postmeta} WHERE meta_key = %s", 'ppwp_post_password_bk' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
|
||||
|
||||
return $this->wpdb->get_results( $sql ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
/**
|
||||
* Count all backup post password.
|
||||
*
|
||||
* @return int - number for count
|
||||
*/
|
||||
public function count_wp_post_passwords() {
|
||||
$sql = $this->wpdb->prepare( "SELECT COUNT(*) FROM {$this->wpdb->postmeta} WHERE meta_key = %s", 'ppwp_post_password_bk' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder
|
||||
|
||||
return $this->wpdb->get_var( $sql ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete selected passwords by id
|
||||
* String will convert to int
|
||||
*
|
||||
* @param array $selected_ids ID Passwords selected.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function bulk_delete_passwords( $selected_ids ) {
|
||||
$selected_ids = implode( ',', array_map( 'absint', $selected_ids ) );
|
||||
$query_string = $this->wpdb->prepare( "DELETE FROM {$this->tbl_name} WHERE ID IN(%1s)", $selected_ids ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- We don't want to set table name as placeholder and put the $ids in quotes.
|
||||
|
||||
return $this->wpdb->query( $query_string ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all expired master password
|
||||
*/
|
||||
public function delete_all_expired_password( $ids, $campaign_app_type) {
|
||||
return $this->wpdb->query($this->wpdb->prepare( "DELETE FROM $this->tbl_name WHERE `campaign_app_type` LIKE '%$campaign_app_type%' and `expired_date` < UNIX_TIMESTAMP(NOW()) or `hits_count` >= `usage_limit`"));
|
||||
//return $this->wpdb->query($this->wpdb->prepare( "DELETE FROM $this->tbl_name WHERE `campaign_app_type` = %s", $campaign_app_type));
|
||||
}
|
||||
|
||||
public function delete_passwords_by_post_id( $post_id ) {
|
||||
return $this->wpdb->delete(
|
||||
$this->tbl_name,
|
||||
array(
|
||||
'post_id' => absint( $post_id ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function find_activated_password( $password, $params ) {
|
||||
$args = wp_parse_args(
|
||||
$params,
|
||||
array(
|
||||
'post_id' => 0,
|
||||
'roles' => array(),
|
||||
'global_type' => '',
|
||||
'role_type' => '',
|
||||
'allow_to_check_expired' => true,
|
||||
)
|
||||
);
|
||||
|
||||
$like_where = '';
|
||||
if ( $args['role_type'] ) {
|
||||
$like_where = $this->generate_where_like_for_roles( $args['roles'], $args['role_type'] );
|
||||
}
|
||||
|
||||
$expired_where = '';
|
||||
if ( $args['allow_to_check_expired'] ) {
|
||||
$expired_where = ' AND (expired_date IS NULL OR expired_date > UNIX_TIMESTAMP()) AND (usage_limit IS NULL OR hits_count < usage_limit) ';
|
||||
}
|
||||
|
||||
$query = $this->wpdb->prepare(
|
||||
"SELECT * FROM {$this->tbl_name} WHERE BINARY password = %s AND is_activated = 1 AND ( campaign_app_type = %s {$like_where}) AND post_id = %d {$expired_where}", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- We don't want to set table name as placeholder and put the extended where sql query in quotes.
|
||||
$password,
|
||||
$args['global_type'],
|
||||
$args['post_id']
|
||||
);
|
||||
|
||||
return $this->wpdb->get_row( $query ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
public function find_activated_passwords_by_ids( $password_ids, $params ) {
|
||||
$args = wp_parse_args(
|
||||
$params,
|
||||
array(
|
||||
'post_id' => 0,
|
||||
'roles' => array(),
|
||||
'global_type' => '',
|
||||
'role_type' => '',
|
||||
'allow_to_check_expired' => true,
|
||||
)
|
||||
);
|
||||
|
||||
$password_ids = array_map( 'absint', $password_ids );
|
||||
$password_ids_str = implode( ', ', $password_ids );
|
||||
$like_where = '';
|
||||
if ( $args['role_type'] ) {
|
||||
$like_where = $this->generate_where_like_for_roles( $args['roles'], $args['role_type'] );
|
||||
}
|
||||
|
||||
$expired_where = '';
|
||||
if ( $args['allow_to_check_expired'] ) {
|
||||
$expired_where = ' AND (expired_date IS NULL OR expired_date > UNIX_TIMESTAMP()) AND (usage_limit IS NULL OR hits_count < usage_limit) ';
|
||||
}
|
||||
|
||||
$query = $this->wpdb->prepare(
|
||||
"SELECT * FROM {$this->tbl_name} WHERE id IN (%1s) AND is_activated = 1 AND ( campaign_app_type = %s {$like_where}) AND post_id = %d {$expired_where}", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- We don't want to set table name as placeholder and put the $ids and the where sql string in quotes.
|
||||
$password_ids_str,
|
||||
$args['global_type'],
|
||||
$args['post_id']
|
||||
);
|
||||
|
||||
return $this->wpdb->get_results( $query ); // phpcs:ignore -- we already prepared above
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate query to get password roles type in DB
|
||||
*
|
||||
* @param array $roles User roles.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generate_where_like_for_roles( $roles, $role_type ) {
|
||||
$where_like_string = '';
|
||||
$pcp_role = $role_type;
|
||||
if ( is_array( $roles ) && count( $roles ) > 0 ) {
|
||||
/**
|
||||
* Generate roles to string with like condition.
|
||||
* Example:
|
||||
* ['editor,'admin'] to ' OR campaign_app_type LIKE '%editor% OR campaign_app_type LIKE '%admin%'
|
||||
*/
|
||||
$where_like_string = array_reduce(
|
||||
$roles,
|
||||
function ( $carry, $role ) use ( $pcp_role ) {
|
||||
if ( ! empty( $role ) ) {
|
||||
$carry = $carry . "OR campaign_app_type LIKE '%{$pcp_role}{$role};%' OR campaign_app_type LIKE '%{$pcp_role}{$role}' ";
|
||||
}
|
||||
|
||||
return $carry;
|
||||
}, $where_like_string );
|
||||
$where_like_string = ! empty( $where_like_string ) ? $where_like_string : '';
|
||||
}
|
||||
|
||||
return $where_like_string;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Fired during plugin deactivation
|
||||
*
|
||||
* @link https://passwordprotectwp.com
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Password_Protect_Page
|
||||
* @subpackage Password_Protect_Page/includes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fired during plugin deactivation.
|
||||
*
|
||||
* This class defines all code necessary to run during the plugin's deactivation.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package Password_Protect_Page
|
||||
* @subpackage Password_Protect_Page/includes
|
||||
* @author BWPS <hello@preventdirectaccess.com>
|
||||
*/
|
||||
class PPW_Deactivator {
|
||||
|
||||
/**
|
||||
* Short Description. (use period)
|
||||
*
|
||||
* Long Description.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function deactivate() {
|
||||
PPW_Options_Services::get_instance()->delete_flag( PPW_Constants::MIGRATED_DEFAULT_PW );
|
||||
PPW_Options_Services::get_instance()->delete_flag( PPW_Constants::MIGRATED_FREE_FLAG );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* PPWP External Settings
|
||||
*/
|
||||
class PPW_External_Settings {
|
||||
/**
|
||||
* Render UI external submenu settings page.
|
||||
*/
|
||||
public function render_ui() {
|
||||
$_get = wp_unslash( $_GET ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We no need to handle nonce verfication for render UI.
|
||||
$head_title = is_pro_active_and_valid_license() ? 'PPWP Pro' : 'PPWP Lite';
|
||||
?>
|
||||
<div class="wrap">
|
||||
<div id="icon-themes" class="icon32"></div>
|
||||
<h2>
|
||||
<?php echo esc_html__( $head_title . ': Integrations', 'password-protect-page' ); ?>
|
||||
</h2>
|
||||
<?php
|
||||
$activated_tab = isset( $_get['tab'] ) ? $_get['tab'] : 'recaptcha';
|
||||
$this->render_tabs( $activated_tab );
|
||||
$this->render_content( $activated_tab );
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Get external tabs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_tabs() {
|
||||
return apply_filters(
|
||||
'ppw_external_tabs',
|
||||
array(
|
||||
array(
|
||||
'tab' => 'recaptcha',
|
||||
'tab_name' => 'reCAPTCHA',
|
||||
),
|
||||
array(
|
||||
'tab' => 'configuration',
|
||||
'tab_name' => 'Configuration',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render tab for external page.
|
||||
*
|
||||
* @param string $active_tab Activate tab
|
||||
*/
|
||||
public function render_tabs( $active_tab ) {
|
||||
$tabs = $this->get_tabs();
|
||||
|
||||
?>
|
||||
<h2 class="ppwp_wrap_tab_title nav-tab-wrapper">
|
||||
<?php
|
||||
if ( ! is_array( $tabs ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $tabs as $tab ) {
|
||||
if ( ! is_array( $tab ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( empty( $tab['tab'] ) || empty( $tab['tab_name'] ) ) {
|
||||
continue;
|
||||
}
|
||||
?>
|
||||
<a href="?page=<?php echo esc_html( PPW_Constants::EXTERNAL_SERVICES_PREFIX ); ?>&tab=<?php echo esc_attr( $tab['tab'] ); ?>"
|
||||
class="nav-tab <?php echo $active_tab === $tab['tab'] ? 'nav-tab-active' : ''; ?>"><?php esc_attr_e( $tab['tab_name'], 'password-protect-page' ); ?></a>
|
||||
<?php } ?>
|
||||
</h2>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render content
|
||||
* @param string $active_tab Active Tab
|
||||
*/
|
||||
|
||||
public function render_content( $active_tab ) {
|
||||
$tabs = $this->get_tabs();
|
||||
foreach ( $tabs as $tab ) {
|
||||
if ( $active_tab === $tab['tab'] ) {
|
||||
do_action( 'ppw_render_external_content_' . $tab['tab'] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,747 @@
|
||||
<?php
|
||||
/**
|
||||
* Check condition and include plugin.php file
|
||||
*/
|
||||
if ( ! function_exists( 'is_plugin_active' ) ) {
|
||||
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape a WP_Error object for passing directly to wp_die().
|
||||
*
|
||||
* The wp_die() function accepts an WP_Error object as the first parameter, but it
|
||||
* does not escape it\'s contents before printing it out to the user. By passing
|
||||
* the object through this function before giving it to wp_die(), the potential for
|
||||
* XSS should be avoided.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* wp_die( my_prefix_escape_wp_error( $error ) );
|
||||
*
|
||||
* @param WP_Error $error The error to escape.
|
||||
*
|
||||
* @return WP_Error The escaped error.
|
||||
*/
|
||||
function ppw_escape_wp_error( $error ) {
|
||||
|
||||
$code = $error->get_error_code();
|
||||
|
||||
$error_data = $error->error_data;
|
||||
|
||||
if ( isset( $error_data[ $code ]['title'] ) ) {
|
||||
$error_data[ $code ]['title'] = wp_kses(
|
||||
$error->error_data[ $code ]['title'],
|
||||
'escape_wp_error_title'
|
||||
);
|
||||
$error->error_data = $error_data;
|
||||
}
|
||||
|
||||
$all_errors = $error->errors;
|
||||
|
||||
foreach ( $all_errors as $code => $errors ) {
|
||||
foreach ( $errors as $key => $message ) {
|
||||
$all_errors[ $code ][ $key ] = wp_kses(
|
||||
$message,
|
||||
'escape_wp_error_message'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$error->errors = $all_errors;
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check data before update setting
|
||||
*
|
||||
* @param array $request Request data.
|
||||
* @param array $setting_keys Keys need to check.
|
||||
* @param bool $is_check_cookie Is check cookie.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function ppw_free_is_setting_data_invalid( $request, $setting_keys, $is_check_cookie = true ) {
|
||||
if ( ppw_free_is_setting_keys_and_nonce_invalid( $request, PPW_Constants::GENERAL_FORM_NONCE ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$settings = $request['settings'];
|
||||
foreach ( $setting_keys as $key ) {
|
||||
if ( ! array_key_exists( $key, $settings ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $is_check_cookie ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check regular expression.
|
||||
return ppw_core_validate_cookie_expiry( $settings[ PPW_Constants::COOKIE_EXPIRED ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check data before update entire site settings
|
||||
*
|
||||
* @param $request
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function ppw_free_is_entire_site_settings_data_invalid( $request ) {
|
||||
return ppw_free_is_setting_keys_and_nonce_invalid( $request, PPW_Constants::ENTIRE_SITE_FORM_NONCE );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $request
|
||||
* @param $nonce_key
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function ppw_free_is_setting_keys_and_nonce_invalid( $request, $nonce_key ) {
|
||||
if ( ! array_key_exists( 'settings', $request ) ||
|
||||
! array_key_exists( 'security_check', $request ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ! wp_verify_nonce( $request['security_check'], $nonce_key ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check error before create new password
|
||||
*
|
||||
* @param $request
|
||||
* @param $setting_keys
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function ppw_free_error_before_create_password( $request, $setting_keys ) {
|
||||
if ( ppw_free_is_setting_keys_and_nonce_invalid( $request, PPW_Constants::META_BOX_NONCE ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$settings = $request["settings"];
|
||||
foreach ( $setting_keys as $key ) {
|
||||
if ( ! array_key_exists( $key, $settings ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate password type is global
|
||||
*
|
||||
* @param $new_global_passwords
|
||||
* @param $current_global_passwords
|
||||
* @param $current_roles_password
|
||||
*/
|
||||
function ppw_free_validate_password_type_global( $new_global_passwords, $current_global_passwords, $current_roles_password ) {
|
||||
if ( count( $new_global_passwords ) < 1 && empty( $current_global_passwords ) ) {
|
||||
wp_send_json(
|
||||
array(
|
||||
'is_error' => true,
|
||||
'message' => PPW_Constants::EMPTY_PASSWORD,
|
||||
),
|
||||
400
|
||||
);
|
||||
wp_die();
|
||||
}
|
||||
|
||||
$global_validate = ppw_free_check_duplicate_global_password( $new_global_passwords, $current_roles_password );
|
||||
if ( $global_validate ) {
|
||||
wp_send_json(
|
||||
array(
|
||||
'is_error' => true,
|
||||
'message' => PPW_Constants::DUPLICATE_PASSWORD,
|
||||
),
|
||||
400
|
||||
);
|
||||
wp_die();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check case duplicate password type is global
|
||||
*
|
||||
* @param $new_global_passwords
|
||||
* @param $current_roles_password
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function ppw_free_check_duplicate_global_password( $new_global_passwords, $current_roles_password ) {
|
||||
if ( empty( $current_roles_password ) ) {
|
||||
return false;
|
||||
}
|
||||
$password_duplicate = array_intersect( $new_global_passwords, array_values( $current_roles_password ) );
|
||||
|
||||
return ! empty( $password_duplicate );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate password type is role
|
||||
*
|
||||
* @param $role_selected
|
||||
* @param $new_role_password
|
||||
* @param $current_global_passwords
|
||||
* @param $current_roles_password
|
||||
*/
|
||||
function ppw_free_validate_password_type_role( $role_selected, $new_role_password, $current_global_passwords, $current_roles_password ) {
|
||||
if ( '' === $new_role_password && ( ! isset( $current_roles_password[ $role_selected ] ) || '' === $current_roles_password[ $role_selected ] ) ) {
|
||||
wp_send_json(
|
||||
array(
|
||||
'is_error' => true,
|
||||
'message' => PPW_Constants::EMPTY_PASSWORD,
|
||||
),
|
||||
400
|
||||
);
|
||||
wp_die();
|
||||
}
|
||||
|
||||
$role_validate = ppw_free_check_duplicate_role_password( $new_role_password, $current_global_passwords );
|
||||
if ( $role_validate ) {
|
||||
wp_send_json(
|
||||
array(
|
||||
'is_error' => true,
|
||||
'message' => PPW_Constants::DUPLICATE_PASSWORD,
|
||||
),
|
||||
400
|
||||
);
|
||||
wp_die();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check case duplicate password type is role
|
||||
*
|
||||
* @param $new_role_password
|
||||
* @param $current_global_passwords
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function ppw_free_check_duplicate_role_password( $new_role_password, $current_global_passwords ) {
|
||||
if ( empty( $current_global_passwords ) ) {
|
||||
return false;
|
||||
}
|
||||
$new_role_password = wp_unslash( $new_role_password );
|
||||
|
||||
return in_array( $new_role_password, $current_global_passwords );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all page and post
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function ppw_free_get_all_page_post() {
|
||||
return array_merge( get_pages(), get_posts( array( 'post_status' => 'publish', 'numberposts' => - 1 ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to fix serialized data
|
||||
* TODO: write UT for this important function
|
||||
*
|
||||
* @param $raw_data
|
||||
* @param $is_un_slashed
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function ppw_free_fix_serialize_data( $raw_data, $is_un_slashed = true ) {
|
||||
if ( ! $raw_data ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if ( ! is_string( $raw_data ) ) {
|
||||
if ( is_array( $raw_data ) ) {
|
||||
return $raw_data;
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
$serialize_raw_data = @unserialize( $raw_data );
|
||||
if ( false === $serialize_raw_data ) {
|
||||
return $raw_data;
|
||||
}
|
||||
|
||||
return $is_un_slashed ? wp_unslash( $serialize_raw_data ) : $serialize_raw_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cookie
|
||||
* @param $expiration
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function ppw_free_bypass_cache_with_cookie_for_pro_version( $cookie, $expiration ) {
|
||||
if ( defined( 'COOKIEHASH' ) ) {
|
||||
$cookie_hash = preg_quote( constant( 'COOKIEHASH' ) );
|
||||
}
|
||||
setcookie( PPW_Constants::WP_POST_PASS . $cookie_hash, $cookie, $expiration, COOKIEPATH, COOKIE_DOMAIN );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check custom login form is showing to avoid conflict with the_password_form default of WordPress.
|
||||
* - Check post type is default type ( post or page )
|
||||
* - Do not show login form product type because we handled it in PPW Pro version. ( woocommerce_before_single_product
|
||||
* hook )
|
||||
* - If Pro version is active then we check protection type in setting to show login form
|
||||
*
|
||||
* @param string $post_type Post Type of Post.
|
||||
*
|
||||
* @return bool True|False Is show login form.
|
||||
*/
|
||||
function ppw_is_post_type_selected_in_setting( $post_type ) {
|
||||
/**
|
||||
* Check default post type
|
||||
* Free & Pro version default: post and page type.
|
||||
*/
|
||||
if ( 'post' === $post_type || 'page' === $post_type ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$is_handle_old_product_type = apply_filters( PPW_Constants::HOOK_HANDLE_BEFORE_RENDER_WOO_PRODUCT, 'product' === $post_type, $post_type );
|
||||
if ( $is_handle_old_product_type || ! class_exists( 'PPW_Pro_Constants' ) ) {
|
||||
return false;
|
||||
}
|
||||
$post_type_selected = ppw_core_get_setting_type_array( PPW_Pro_Constants::WPP_WHITELIST_COLUMN_PROTECTIONS );
|
||||
|
||||
/**
|
||||
* Check post type in setting which user selected.
|
||||
*/
|
||||
return in_array( $post_type, $post_type_selected, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post_id from referer url if Post data is not exist post_id.
|
||||
*
|
||||
* @return int post_id Post ID, 0 if post id not exist.
|
||||
*/
|
||||
function ppw_get_post_id_from_request() {
|
||||
$_server = wp_unslash( $_SERVER );
|
||||
$_post = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- We no need to handle nonce verification for this function.
|
||||
if ( isset( $_post['post_id'] ) ) {
|
||||
return (int) wp_unslash( $_post['post_id'] );
|
||||
}
|
||||
/**
|
||||
* Make sure http referer on server.
|
||||
* Not make exception in url_to_postid.
|
||||
*/
|
||||
if ( ! isset( $_server['HTTP_REFERER'] ) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get post id from referer url.
|
||||
return url_to_postid( $_server['HTTP_REFERER'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* WP introduced is_wp_version_compatible function from version 5.2.0 only.
|
||||
* (https://developer.wordpress.org/reference/functions/is_wp_version_compatible/)
|
||||
* Need to write the helper by our-self.
|
||||
*
|
||||
* @param string $required Version to check.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function ppw_is_wp_version_compatible( $required ) {
|
||||
return empty( $required ) || version_compare( get_bloginfo( 'version' ), $required, '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page title for home, category, tag or post
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function ppw_get_page_title() {
|
||||
$site_title = get_bloginfo( 'title' );
|
||||
$site_description = get_bloginfo( 'description' );
|
||||
$post_title = wp_title( '', false ); // Post title, category tile, tag title.
|
||||
$dash_score_site = '' === $site_title || '' === $site_description ? '' : ' – ';
|
||||
$dash_score_post = '' === $site_title || '' === $post_title ? '' : ' – ';
|
||||
|
||||
return is_home() || is_front_page()
|
||||
? sprintf( '%1$s%2$s%3$s', $site_title, $dash_score_site, $site_description )
|
||||
: sprintf( '%1$s%2$s%3$s', $post_title, $dash_score_post, $site_title );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post excerpt if post is protected via Settings.
|
||||
*
|
||||
* @param WP_Post $post Post WordPress Object.
|
||||
* @param string $content Content of post.
|
||||
* @param bool $is_show_excerpt Is show excerpt.
|
||||
* TODO: Need to refactor logic for this function.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function ppw_handle_protected_content( $post, $content, $is_show_excerpt ) {
|
||||
if ( $is_show_excerpt && $post->post_excerpt ) {
|
||||
$content = $post->post_excerpt . $content;
|
||||
}
|
||||
|
||||
if ( ! is_singular() && ! preg_match( '/name=.+post_id/mi', $content ) ) {
|
||||
$content = '<em>[This is password-protected.]</em>';
|
||||
|
||||
return apply_filters( 'the_ppw_password_message', $content );
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to get Pro version.
|
||||
*/
|
||||
function ppw_get_pro_version() {
|
||||
if ( ! defined( 'PPW_PRO_VERSION' ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return PPW_PRO_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bypass function using to
|
||||
* - Display feed content when user turn on sitewide protection.
|
||||
*
|
||||
* @return bool True is bypass sitewide.
|
||||
*/
|
||||
function ppw_free_has_bypass_sitewide_protection() {
|
||||
$has_bypass = defined( 'PPWP_SITEWIDE_FEED_DISPLAY' ) && PPWP_SITEWIDE_FEED_DISPLAY && is_feed();
|
||||
|
||||
return apply_filters( 'ppwp_sitewide_has_bypass', $has_bypass );
|
||||
}
|
||||
|
||||
/**
|
||||
* Bypass function using to
|
||||
* - Display feed content when post/page is protected by single protection.
|
||||
*
|
||||
* @return bool True is bypass post_password_required.
|
||||
*/
|
||||
function ppw_free_has_bypass_single_protection() {
|
||||
$has_bypass = defined( 'PPWP_SINGLE_FEED_DISPLAY' ) && PPWP_SINGLE_FEED_DISPLAY && is_feed();
|
||||
|
||||
return apply_filters( 'ppwp_single_has_bypass', $has_bypass );
|
||||
}
|
||||
|
||||
/**
|
||||
* Has support PPWP shortcode for page builder.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function ppw_free_has_support_shortcode_page_builder() {
|
||||
// Have user turn on option.
|
||||
$enabled = ppw_core_get_setting_type_bool_by_option_name( PPW_Constants::USE_SHORTCODE_PAGE_BUILDER, PPW_Constants::SHORTCODE_OPTIONS );
|
||||
|
||||
return apply_filters( 'ppwp_shortcode_enable_page_builder', $enabled );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the plaintext password against the encrypted Password.
|
||||
*
|
||||
* @param string $password Plaintext user's password
|
||||
* @param string $hash Hash of the user's password to check against.
|
||||
*
|
||||
* @return bool False, if the $password does not match the hashed password
|
||||
* @link https://developer.wordpress.org/reference/functions/wp_check_password/
|
||||
*/
|
||||
function ppw_free_check_password( $password, $hash ) {
|
||||
global $wp_hasher;
|
||||
// If the stored hash is longer than an MD5,
|
||||
// presume the new style phpass portable hash.
|
||||
if ( empty( $wp_hasher ) ) {
|
||||
require_once ABSPATH . WPINC . '/class-phpass.php';
|
||||
// By default, use the portable hash from phpass.
|
||||
$wp_hasher = new PasswordHash( 8, true );
|
||||
}
|
||||
|
||||
return $wp_hasher->CheckPassword( $password, $hash );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the shortcode matches for searching.
|
||||
*
|
||||
* @param $content
|
||||
*
|
||||
* @return array The regular expression contains 6 different sub matches to help with parsing.
|
||||
* 1 - An extra [ to allow for escaping shortcodes with double [[]]
|
||||
* 2 – The shortcode name
|
||||
* 3 – The shortcode argument list
|
||||
* 4 – The self closing /
|
||||
* 5 – The content of a shortcode when it wraps some content.
|
||||
* 6 – An extra ] to allow for escaping shortcodes with double [[]]
|
||||
*/
|
||||
function ppw_free_search_shortcode_content( $content ) {
|
||||
preg_match_all( '/' . get_shortcode_regex( array( 'ppwp' ) ) . '/', $content, $matches, PREG_SET_ORDER );
|
||||
|
||||
return $matches;
|
||||
}
|
||||
|
||||
function ppw_free_valid_pcp_password( $shortcode, $password ) {
|
||||
$default_args = array(
|
||||
'is_valid_password' => false,
|
||||
'atts' => array(),
|
||||
);
|
||||
// Check ppwp shortcode exist.
|
||||
if ( PPW_Constants::PPW_HOOK_SHORT_CODE_NAME !== $shortcode[2] || ! isset( $shortcode[3] ) ) {
|
||||
return $default_args;
|
||||
}
|
||||
// Parse shortcode string to array.
|
||||
$parsed_atts = shortcode_parse_atts( trim( $shortcode[3] ) );
|
||||
|
||||
// Get attributes from shortcode.
|
||||
$atts = PPW_Shortcode::get_instance()->get_attributes( $parsed_atts );
|
||||
$passwords = apply_filters( PPW_Constants::HOOK_SHORTCODE_PASSWORDS, array_filter( $atts['passwords'], 'strlen' ), $parsed_atts );
|
||||
|
||||
// Check password exist.
|
||||
if ( in_array( $password, $passwords, true ) ) {
|
||||
$default_args['is_valid_password'] = true;
|
||||
$default_args['atts'] = $atts;
|
||||
}
|
||||
|
||||
if ( isset( $parsed_atts['error_msg'] ) ) {
|
||||
$default_args['message'] = wp_kses_post( $parsed_atts['error_msg'] );
|
||||
}
|
||||
|
||||
return apply_filters( 'ppw_validated_pcp_password', $default_args, $password, $parsed_atts, $shortcode );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate date.
|
||||
*
|
||||
* @param $date
|
||||
* @param string $format
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function ppw_free_validate_date( $date ) {
|
||||
return false !== strtotime( $date );
|
||||
}
|
||||
|
||||
function ppw_get_background_image( $image ) {
|
||||
$img = get_theme_mod( 'ppwp_pro_form_background_image', '' );
|
||||
if ( ! empty( $img ) ) {
|
||||
return $img;
|
||||
}
|
||||
|
||||
return PPW_DIR_URL . 'includes/customizers/assets/images/backgrounds/' . $image;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Support with builder plugin.
|
||||
*
|
||||
* @param integer $post_id Post ID.
|
||||
* @param string $post_content Post Content.
|
||||
*
|
||||
* @return string Post Content.
|
||||
*/
|
||||
function ppw_support_third_party_content_plugin( $post_id, $post_content ) {
|
||||
if ( method_exists( '\WPBMap', 'addAllMappedShortcodes' ) ) {
|
||||
\WPBMap::addAllMappedShortcodes();
|
||||
}
|
||||
if ( class_exists( '\TablePress' ) ) {
|
||||
\TablePress::$controller = \TablePress::load_controller( 'frontend' );
|
||||
\TablePress::$controller->init_shortcodes();
|
||||
}
|
||||
if ( class_exists( '\\Elementor\\Plugin' ) ) {
|
||||
if ( \Elementor\Plugin::$instance->db->is_built_with_elementor( $post_id ) ) {
|
||||
// Disable function check post_password_required because need to get content show to user.
|
||||
remove_all_filters( 'post_password_required' );
|
||||
$post_content = \Elementor\Plugin::$instance->frontend->get_builder_content( $post_id, true );
|
||||
}
|
||||
}
|
||||
|
||||
return apply_filters( 'ppw_content_compatibility', $post_content );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PPWP Pro plugin data version.
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
function ppw_get_pro_data_version() {
|
||||
if ( defined( 'PPW_PRO_VERSION' ) ) {
|
||||
return PPW_PRO_VERSION;
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'get_plugins' )
|
||||
|| ! function_exists( 'is_plugin_active' )
|
||||
|| ! function_exists( 'get_plugins' )
|
||||
) {
|
||||
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
||||
}
|
||||
|
||||
// Check plugin is active from option data.
|
||||
if ( ! is_plugin_active( PPW_Constants::PRO_DIRECTORY ) && ! is_plugin_active( PPW_Constants::DEV_PRO_DIRECTORY ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get plugin version from file.
|
||||
$installed_plugins = get_plugins();
|
||||
|
||||
// Get Pro Production folder version.
|
||||
if ( isset( $installed_plugins[ PPW_Constants::PRO_DIRECTORY ], $installed_plugins[ PPW_Constants::PRO_DIRECTORY ]['Version'] ) ) {
|
||||
return $installed_plugins[ PPW_Constants::PRO_DIRECTORY ]['Version'];
|
||||
}
|
||||
|
||||
// Get Pro Development folder version.
|
||||
if ( isset( $installed_plugins[ PPW_Constants::DEV_PRO_DIRECTORY ], $installed_plugins[ PPW_Constants::DEV_PRO_DIRECTORY ]['Version'] ) ) {
|
||||
return $installed_plugins[ PPW_Constants::DEV_PRO_DIRECTORY ]['Version'];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get allowed capability.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function ppw_get_allowed_capability() {
|
||||
if ( current_user_can( 'manage_options' ) ) {
|
||||
return 'manage_options';
|
||||
}
|
||||
|
||||
return 'ppwp_manage_options';
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow user to display all PPWP option.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function ppw_allow_manage_passwords() {
|
||||
$capability = ppw_get_allowed_capability();
|
||||
|
||||
return current_user_can( $capability ) || current_user_can( 'edit_posts' );
|
||||
}
|
||||
|
||||
function ppw_allowed_master_protection_type() {
|
||||
return apply_filters( 'ppw_allowed_master_protection_type', false );
|
||||
}
|
||||
|
||||
function ppw_get_current_user_agent() {
|
||||
return ! empty( $server_env['HTTP_USER_AGENT'] ) ? $server_env['HTTP_USER_AGENT'] : 'N/A';
|
||||
}
|
||||
|
||||
function ppw_get_current_ip_address() {
|
||||
$server = wp_unslash( $_SERVER );
|
||||
if ( ! empty( $server['HTTP_CF_CONNECTING_IP'] ) ) {
|
||||
return $server['HTTP_CF_CONNECTING_IP'];
|
||||
}
|
||||
|
||||
if ( ! empty( $server['HTTP_CLIENT_IP'] ) ) {
|
||||
return $server['HTTP_CLIENT_IP'];
|
||||
}
|
||||
|
||||
if ( ! empty( $server['HTTP_X_FORWARDED_FOR'] ) ) {
|
||||
return $server['HTTP_X_FORWARDED_FOR'];
|
||||
}
|
||||
|
||||
return $server['REMOTE_ADDR'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function ppw_get_current_username() {
|
||||
$current_user = wp_get_current_user();
|
||||
return 0 === $current_user->ID ? 'N/A' : $current_user->user_login;
|
||||
}
|
||||
|
||||
function ppw_tracking_master_password( $post_id, $password, $type = 'single' ) {
|
||||
$meta_data = array(
|
||||
'protection_type' => $type,
|
||||
);
|
||||
$meta_data = apply_filters( 'ppw_master_pcp_password_meta', $meta_data );
|
||||
$meta_data_encoded = wp_json_encode( $meta_data );
|
||||
$data = array(
|
||||
'user_agent' => ppw_get_current_user_agent(),
|
||||
'ip_address' => ppw_get_current_ip_address(),
|
||||
'password' => $password,
|
||||
'username' => ppw_get_current_username(),
|
||||
'post_type' => 'ppwp_master',
|
||||
'access_date' => time(),
|
||||
'post_id' => $post_id,
|
||||
'meta_data' => $meta_data_encoded,
|
||||
);
|
||||
|
||||
do_action( 'ppwp_track_password', $data );
|
||||
}
|
||||
|
||||
function ppw_get_pcp_post_content_with_third_party( $post, $index ) {
|
||||
$allowed = did_action( 'elementor/loaded' );
|
||||
$allowed = apply_filters( 'ppw_pcp_third_party_content_allowed', $allowed );
|
||||
if ( ! $allowed ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setup_postdata( $post );
|
||||
$post_content = ppw_support_third_party_content_plugin( $post->ID, false );
|
||||
if ( empty( $post_content ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
wp_reset_postdata();
|
||||
$matches = ppw_free_search_shortcode_content( $post_content );
|
||||
if ( isset( $matches[ $index ] ) ) {
|
||||
$new_shortcode = $matches[ $index ];
|
||||
|
||||
return isset( $new_shortcode[5] ) ? $new_shortcode[5] : false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function ppw_get_value( $data, $key, $default = '' ) {
|
||||
if ( ! isset( $data[ $key ] ) ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return $data[ $key ];
|
||||
}
|
||||
|
||||
function ppw_free_render_sidebar() {
|
||||
if ( ! is_pro_active_and_valid_license() ) {
|
||||
include PPW_DIR_PATH . 'includes/views/sidebar/view-ppw-sidebar.php';
|
||||
} else {
|
||||
do_action( PPW_Constants::HOOK_SIDEBAR_SHORTCODE );
|
||||
}
|
||||
}
|
||||
|
||||
function ppw_get_utc() {
|
||||
$min = 60 * get_option('gmt_offset');
|
||||
$sign = $min < 0 ? "-" : "+";
|
||||
$absmin = abs($min);
|
||||
return sprintf("UTC%s%02d:%02d", $sign, $absmin/60, $absmin%60);
|
||||
}
|
||||
|
||||
function ppw_get_terms_with_all_lang( $args ) {
|
||||
global $sitepress;
|
||||
|
||||
if ( $sitepress ) {
|
||||
remove_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ) );
|
||||
remove_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ) );
|
||||
remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) );
|
||||
|
||||
$terms = get_terms( $args );
|
||||
|
||||
add_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ), 10, 4 );
|
||||
add_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ), 1, 1 );
|
||||
add_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ), 10, 2 );
|
||||
} else {
|
||||
$terms = get_terms( $args );
|
||||
}
|
||||
|
||||
return $terms;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Define the internationalization functionality
|
||||
*
|
||||
* Loads and defines the internationalization files for this plugin
|
||||
* so that it is ready for translation.
|
||||
*
|
||||
* @link https://passwordprotectwp.com
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Password_Protect_Page
|
||||
* @subpackage Password_Protect_Page/includes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Define the internationalization functionality.
|
||||
*
|
||||
* Loads and defines the internationalization files for this plugin
|
||||
* so that it is ready for translation.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package Password_Protect_Page
|
||||
* @subpackage Password_Protect_Page/includes
|
||||
* @author BWPS <hello@preventdirectaccess.com>
|
||||
*/
|
||||
class PPW_i18n {
|
||||
|
||||
|
||||
/**
|
||||
* Load the plugin text domain for translation.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function load_plugin_textdomain() {
|
||||
|
||||
load_plugin_textdomain(
|
||||
'password-protect-page',
|
||||
false,
|
||||
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Register all actions and filters for the plugin
|
||||
*
|
||||
* @link https://passwordprotectwp.com
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Password_Protect_Page
|
||||
* @subpackage Password_Protect_Page/includes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Register all actions and filters for the plugin.
|
||||
*
|
||||
* Maintain a list of all hooks that are registered throughout
|
||||
* the plugin, and register them with the WordPress API. Call the
|
||||
* run function to execute the list of actions and filters.
|
||||
*
|
||||
* @package Password_Protect_Page
|
||||
* @subpackage Password_Protect_Page/includes
|
||||
* @author BWPS <hello@preventdirectaccess.com>
|
||||
*/
|
||||
class PPW_Loader {
|
||||
|
||||
/**
|
||||
* The array of actions registered with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @var array $actions The actions registered with WordPress to fire when the plugin loads.
|
||||
*/
|
||||
protected $actions;
|
||||
|
||||
/**
|
||||
* The array of filters registered with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @var array $filters The filters registered with WordPress to fire when the plugin loads.
|
||||
*/
|
||||
protected $filters;
|
||||
|
||||
/**
|
||||
* Initialize the collections used to maintain the actions and filters.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->actions = array();
|
||||
$this->filters = array();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new action to the collection to be registered with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param string $hook The name of the WordPress action that is being registered.
|
||||
* @param object $component A reference to the instance of the object on which the action is defined.
|
||||
* @param string $callback The name of the function definition on the $component.
|
||||
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
|
||||
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
|
||||
*/
|
||||
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new filter to the collection to be registered with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param string $hook The name of the WordPress filter that is being registered.
|
||||
* @param object $component A reference to the instance of the object on which the filter is defined.
|
||||
* @param string $callback The name of the function definition on the $component.
|
||||
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
|
||||
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
|
||||
*/
|
||||
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new short code to the collection to be registered with WordPress.
|
||||
*
|
||||
* @param $tag
|
||||
* @param $component
|
||||
* @param $callback
|
||||
*/
|
||||
public function add_shortcode ( $tag, $component, $callback ) {
|
||||
add_shortcode( $tag, array ( $component, $callback) );
|
||||
}
|
||||
/**
|
||||
* A utility function that is used to register the actions and hooks into a single
|
||||
* collection.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
|
||||
* @param string $hook The name of the WordPress filter that is being registered.
|
||||
* @param object $component A reference to the instance of the object on which the filter is defined.
|
||||
* @param string $callback The name of the function definition on the $component.
|
||||
* @param int $priority The priority at which the function should be fired.
|
||||
* @param int $accepted_args The number of arguments that should be passed to the $callback.
|
||||
* @return array The collection of actions and filters registered with WordPress.
|
||||
*/
|
||||
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
|
||||
|
||||
$hooks[] = array(
|
||||
'hook' => $hook,
|
||||
'component' => $component,
|
||||
'callback' => $callback,
|
||||
'priority' => $priority,
|
||||
'accepted_args' => $accepted_args
|
||||
);
|
||||
|
||||
return $hooks;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the filters and actions with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function run() {
|
||||
|
||||
foreach ( $this->filters as $hook ) {
|
||||
add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
|
||||
}
|
||||
|
||||
foreach ( $this->actions as $hook ) {
|
||||
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* PPWP Partial Protection Settings
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'PPW_Partial_Protection_Settings' ) ) {
|
||||
class PPW_Partial_Protection_Settings {
|
||||
|
||||
/**
|
||||
* Render UI for Partial Protection page.
|
||||
*/
|
||||
public function render_ui() {
|
||||
$_get = wp_unslash( $_GET ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We no need to handle nonce verfication for render UI.
|
||||
$head_title = is_pro_active_and_valid_license() ? 'PPWP Pro' : 'PPWP Lite';
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h2><?php echo esc_html__( $head_title . ': Partial Protection', 'password-protect-page' ) ?></h2>
|
||||
<?php
|
||||
$default_tab = apply_filters( PPW_Constants::HOOK_PCP_TAB, 'general' );
|
||||
$active_tab = isset( $_get['tab'] ) ? $_get['tab'] : $default_tab;
|
||||
$this->render_tabs( $active_tab );
|
||||
$this->render_content( $active_tab );
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render tab for Partial Protection page.
|
||||
*
|
||||
* @param string $active_tab Active tab.
|
||||
*/
|
||||
public function render_tabs( $active_tab ) {
|
||||
$tabs = apply_filters(
|
||||
PPW_Constants::HOOK_ADD_NEW_PCP_SUBMENU,
|
||||
array(
|
||||
array(
|
||||
'tab' => 'general',
|
||||
'tab_name' => 'General',
|
||||
),
|
||||
)
|
||||
);
|
||||
?>
|
||||
<h2 class="ppwp_wrap_tab_title nav-tab-wrapper">
|
||||
<?php
|
||||
if ( ! is_array( $tabs ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $tabs as $tab ) {
|
||||
if ( ! is_array( $tab ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( empty( $tab['tab'] ) || empty( $tab['tab_name'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( isset( $tab['link'] ) ) {
|
||||
$link = $tab['link'];
|
||||
} else {
|
||||
$link = '?page=' . esc_html( PPW_Constants::PCP_PAGE_PREFIX ) . '&tab=' . esc_attr( $tab['tab'] );
|
||||
}
|
||||
|
||||
?>
|
||||
<a href="<?php echo esc_url( $link ); ?>"
|
||||
class="nav-tab <?php echo $active_tab === $tab['tab'] ? 'nav-tab-active' : ''; ?>"><?php esc_attr_e( $tab['tab_name'], 'password-protect-page' ); ?></a>
|
||||
<?php } ?>
|
||||
</h2>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render content for Partial Protection page.
|
||||
*
|
||||
* @param string $active_tab Active tab.
|
||||
*/
|
||||
public function render_content( $active_tab ) {
|
||||
$tabs = apply_filters( PPW_Constants::HOOK_CUSTOM_PCP_TAB, array( 'general' ) );
|
||||
|
||||
foreach ( $tabs as $tab ) {
|
||||
if ( $active_tab === $tab ) {
|
||||
do_action( PPW_Constants::HOOK_RENDER_CONTENT_FOR_PCP_TAB . $tab );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* PPWP Settings
|
||||
*/
|
||||
if ( ! class_exists( "PPW_Settings" ) ) {
|
||||
class PPW_Settings {
|
||||
/**
|
||||
* Render UI settings page
|
||||
*/
|
||||
public function render_ui() {
|
||||
$_get = wp_unslash( $_GET ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We no need to handle nonce verification for render UI.
|
||||
$plugin_info = apply_filters( PPW_Constants::HOOK_PLUGIN_INFO, array(
|
||||
'name' => 'Password Protect WordPress - PPWP',
|
||||
'version' => PPW_VERSION,
|
||||
) );
|
||||
?>
|
||||
<div class="wrap">
|
||||
<div id="icon-themes" class="icon32"></div>
|
||||
<h2>
|
||||
<?php esc_html_e( $plugin_info['name'], 'password-protect-page' ); ?>
|
||||
<span class="ppwp_version"><?php esc_html_e( $plugin_info['version'] ) ?></span>
|
||||
</h2>
|
||||
<?php
|
||||
$default_tab = apply_filters( PPW_Constants::HOOK_DEFAULT_TAB, 'general' );
|
||||
$activate_tab = isset( $_get['tab'] ) ? $_get['tab'] : $default_tab;
|
||||
$this->render_tabs( $activate_tab );
|
||||
$this->render_content( $activate_tab );
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render tab for settings page
|
||||
*
|
||||
* @param string $active_tab Active tab.
|
||||
*/
|
||||
private function render_tabs( $active_tab ) {
|
||||
$tabs = apply_filters(
|
||||
PPW_Constants::HOOK_ADD_NEW_TAB,
|
||||
array(
|
||||
array(
|
||||
'tab' => 'general',
|
||||
'tab_name' => 'General',
|
||||
),
|
||||
array(
|
||||
'tab' => 'misc',
|
||||
'tab_name' => 'Advanced',
|
||||
),
|
||||
array(
|
||||
'tab' => 'entire_site',
|
||||
'tab_name' => 'Sitewide',
|
||||
),
|
||||
array(
|
||||
'tab' => 'shortcodes',
|
||||
'tab_name' => 'Shortcodes',
|
||||
),
|
||||
array(
|
||||
'tab' => 'master_passwords',
|
||||
'tab_name' => 'Master Passwords',
|
||||
),
|
||||
array(
|
||||
'tab' => 'troubleshooting',
|
||||
'tab_name' => 'Troubleshooting',
|
||||
)
|
||||
)
|
||||
);
|
||||
?>
|
||||
<h2 class="ppwp_wrap_tab_title nav-tab-wrapper">
|
||||
<?php
|
||||
if ( ! is_array( $tabs ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $tabs as $tab ) {
|
||||
if ( ! is_array( $tab ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( empty( $tab['tab'] ) || empty( $tab['tab_name'] ) ) {
|
||||
continue;
|
||||
}
|
||||
?>
|
||||
<a href="?page=<?php echo esc_html( PPW_Constants::MENU_NAME ); ?>&tab=<?php echo esc_attr( $tab['tab'] ); ?>"
|
||||
class="nav-tab <?php echo $active_tab === $tab['tab'] ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( $tab['tab_name'], PPW_Constants::DOMAIN ); ?></a>
|
||||
<?php } ?>
|
||||
</h2>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render content for settings page
|
||||
*
|
||||
* @param string $active_tab Active tab.
|
||||
*/
|
||||
private function render_content( $active_tab ) {
|
||||
$tabs = apply_filters( PPW_Constants::HOOK_CUSTOM_TAB, array( 'general', 'misc', 'entire_site', 'shortcodes', 'master_passwords', 'troubleshooting' ) );
|
||||
|
||||
foreach ( $tabs as $tab ) {
|
||||
if ( $active_tab === $tab ) {
|
||||
do_action( PPW_Constants::HOOK_RENDER_CONTENT_FOR_TAB . $tab );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* PPWP Sitewide Settings
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'PPW_Sitewide_Settings' ) ) {
|
||||
class PPW_Sitewide_Settings {
|
||||
/**
|
||||
* Render UI sitewide submenu settings page
|
||||
*/
|
||||
public function render_ui() {
|
||||
$_get = wp_unslash( $_GET ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We no need to handle nonce verification for render UI.
|
||||
$head_title = is_pro_active_and_valid_license() ? 'PPWP Pro' : 'PPWP Lite';
|
||||
?>
|
||||
<div class="wrap">
|
||||
<div id="icon-themes" class="icon32"></div>
|
||||
<h2>
|
||||
<?php echo esc_html__( $head_title . ': Sitewide Protection', 'password-protect-page' ); ?>
|
||||
</h2>
|
||||
<?php
|
||||
$general_tab = apply_filters( PPW_Constants::HOOK_SITEWIDE_TAB, 'general' );
|
||||
$activated_tab = isset( $_get['tab'] ) ? $_get['tab'] : $general_tab;
|
||||
$this->render_tabs( $activated_tab );
|
||||
$this->render_content( $activated_tab );
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render tab for sitewide page
|
||||
*
|
||||
* @param string $active_tab Activate tab
|
||||
*/
|
||||
public function render_tabs( $active_tab ) {
|
||||
$tabs = apply_filters(
|
||||
PPW_Constants::HOOK_ADD_NEW_SITEWIDE_SUBMENU,
|
||||
array(
|
||||
array(
|
||||
'tab' => 'general',
|
||||
'tab_name' => 'General',
|
||||
),
|
||||
)
|
||||
);
|
||||
?>
|
||||
<h2 class="ppwp_wrap_tab_title nav-tab-wrapper">
|
||||
<?php
|
||||
if ( ! is_array( $tabs ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $tabs as $tab ) {
|
||||
if ( ! is_array( $tab ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( empty( $tab['tab'] ) || empty( $tab['tab_name'] ) ) {
|
||||
continue;
|
||||
}
|
||||
?>
|
||||
<a href="?page=<?php echo esc_html( PPW_Constants::SITEWIDE_PAGE_PREFIX ); ?>&tab=<?php echo esc_attr( $tab['tab'] ); ?>"
|
||||
class="nav-tab <?php echo $active_tab === $tab['tab'] ? 'nav-tab-active' : ''; ?>"><?php esc_attr_e( $tab['tab_name'], PPW_Constants::DOMAIN ); ?></a>
|
||||
<?php } ?>
|
||||
</h2>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the content
|
||||
* @param string $active_tab Active Tab
|
||||
*/
|
||||
public function render_content( $active_tab ) {
|
||||
$tabs = apply_filters( PPW_Constants::HOOK_CUSTOM_SITEWIDE_TAB, array( 'general' ) );
|
||||
|
||||
foreach ( $tabs as $tab ) {
|
||||
if ( $active_tab === $tab ) {
|
||||
do_action( PPW_Constants::HOOK_RENDER_CONTENT_FOR_SITEWIDE_TAB . $tab );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* PPWP Class for Uninstall plugin
|
||||
*/
|
||||
if ( ! class_exists( 'PPW_Uninstall' ) ) {
|
||||
class PPW_Uninstall {
|
||||
/**
|
||||
* Uninstall plugin
|
||||
*/
|
||||
public static function uninstall() {
|
||||
self::handle_uninstall_plugin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle uninstall plugin
|
||||
*/
|
||||
private static function handle_uninstall_plugin() {
|
||||
if ( is_multisite() ) {
|
||||
foreach ( get_sites() as $site ) {
|
||||
$blog_id = $site->blog_id;
|
||||
if ( ppw_core_get_setting_type_bool( PPW_Constants::REMOVE_DATA, $blog_id ) ) {
|
||||
global $wpdb;
|
||||
self::delete_general_option( $blog_id );
|
||||
self::delete_entire_site_option( $blog_id );
|
||||
$wp_prefix = $wpdb->get_blog_prefix( $blog_id );
|
||||
ppw_core_delete_data_in_post_meta_by_meta_key( PPW_Constants::POST_PROTECTION_ROLES, $wp_prefix );
|
||||
ppw_core_delete_data_in_post_meta_by_meta_key( PPW_Constants::GLOBAL_PASSWORDS, $wp_prefix );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( ppw_core_get_setting_type_bool( PPW_Constants::REMOVE_DATA ) ) {
|
||||
self::delete_general_option();
|
||||
self::delete_entire_site_option();
|
||||
ppw_core_delete_data_in_post_meta_by_meta_key( PPW_Constants::POST_PROTECTION_ROLES );
|
||||
ppw_core_delete_data_in_post_meta_by_meta_key( PPW_Constants::GLOBAL_PASSWORDS );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle delete general option
|
||||
*
|
||||
* @param $site_id
|
||||
*/
|
||||
private static function delete_general_option( $site_id = false ) {
|
||||
$settings = ! $site_id ? get_option( PPW_Constants::GENERAL_OPTIONS ) : get_blog_option( $site_id, PPW_Constants::GENERAL_OPTIONS );
|
||||
if ( ! $settings ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$options = json_decode( $settings );
|
||||
if ( ! is_object( $options ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$new_options = (array) $options;
|
||||
unset( $new_options[ PPW_Constants::COOKIE_EXPIRED ] );
|
||||
unset( $new_options[ PPW_Constants::REMOVE_DATA ] );
|
||||
if ( ! $site_id ) {
|
||||
update_option( PPW_Constants::GENERAL_OPTIONS, wp_json_encode( $new_options ) );
|
||||
} else {
|
||||
update_blog_option( $site_id, PPW_Constants::GENERAL_OPTIONS, wp_json_encode( $new_options ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle delete entire site option
|
||||
*
|
||||
* @param $site_id
|
||||
*/
|
||||
private static function delete_entire_site_option( $site_id = false ) {
|
||||
$options = ! $site_id ? get_option( PPW_Constants::ENTIRE_SITE_OPTIONS ) : get_blog_option( $site_id, PPW_Constants::ENTIRE_SITE_OPTIONS );
|
||||
if ( ! $options ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_array( $options ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
unset( $options[ PPW_Constants::IS_PROTECT_ENTIRE_SITE ] );
|
||||
unset( $options[ PPW_Constants::PASSWORD_ENTIRE_SITE ] );
|
||||
if ( ! $site_id ) {
|
||||
update_option( PPW_Constants::ENTIRE_SITE_OPTIONS, $options );
|
||||
} else {
|
||||
update_blog_option( $site_id, PPW_Constants::ENTIRE_SITE_OPTIONS, $options );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
478
wp-content/plugins/password-protect-page/includes/class-ppw.php
Normal file
@@ -0,0 +1,478 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The file that defines the core plugin class
|
||||
*
|
||||
* A class definition that includes attributes and functions used across both the
|
||||
* public-facing side of the site and the admin area.
|
||||
*
|
||||
* @link https://passwordprotectwp.com
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Password_Protect_Page
|
||||
* @subpackage Password_Protect_Page/includes
|
||||
*/
|
||||
|
||||
/**
|
||||
* The core plugin class.
|
||||
*
|
||||
* This is used to define internationalization, admin-specific hooks, and
|
||||
* public-facing site hooks.
|
||||
*
|
||||
* Also maintains the unique identifier of this plugin as well as the current
|
||||
* version of the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package Password_Protect_Page
|
||||
* @subpackage Password_Protect_Page/includes
|
||||
* @author BWPS <hello@preventdirectaccess.com>
|
||||
*/
|
||||
class Password_Protect_Page {
|
||||
|
||||
/**
|
||||
* The loader that's responsible for maintaining and registering all hooks that power
|
||||
* the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @var PPW_Loader $loader Maintains and registers all hooks for the plugin.
|
||||
*/
|
||||
protected $loader;
|
||||
|
||||
/**
|
||||
* The unique identifier of this plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @var string $plugin_name The string used to uniquely identify this plugin.
|
||||
*/
|
||||
protected $plugin_name;
|
||||
|
||||
/**
|
||||
* The current version of the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @var string $version The current version of the plugin.
|
||||
*/
|
||||
protected $version;
|
||||
|
||||
/**
|
||||
* Define the core functionality of the plugin.
|
||||
*
|
||||
* Set the plugin name and the plugin version that can be used throughout the plugin.
|
||||
* Load the dependencies, define the locale, and set the hooks for the admin area and
|
||||
* the public-facing side of the site.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
if ( defined( 'PPW_VERSION' ) ) {
|
||||
$this->version = PPW_VERSION;
|
||||
} else {
|
||||
$this->version = '1.0.0';
|
||||
}
|
||||
$this->plugin_name = 'password-protect-page';
|
||||
|
||||
$this->load_dependencies();
|
||||
$this->set_locale();
|
||||
$this->define_admin_hooks();
|
||||
$this->define_public_hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the required dependencies for this plugin.
|
||||
*
|
||||
* Include the following files that make up the plugin:
|
||||
*
|
||||
* - Password_Protect_Page_Loader. Orchestrates the hooks of the plugin.
|
||||
* - Password_Protect_Page_i18n. Defines internationalization functionality.
|
||||
* - Password_Protect_Page_Admin. Defines all hooks for the admin area.
|
||||
* - Password_Protect_Page_Public. Defines all hooks for the public side of the site.
|
||||
*
|
||||
* Create an instance of the loader which will be used to register the hooks
|
||||
* with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*/
|
||||
private function load_dependencies() {
|
||||
/**
|
||||
* The class responsible for orchestrating the actions and filters of the
|
||||
* core plugin.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ppw-loader.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining internationalization functionality
|
||||
* of the plugin.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ppw-i18n.php';
|
||||
|
||||
/**
|
||||
* Require Constants
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ppw-constants.php';
|
||||
|
||||
/**
|
||||
* Require Functions
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ppw-functions.php';
|
||||
|
||||
/**
|
||||
* Require Service Interfaces
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'core/class-ppw-service-interfaces.php';
|
||||
|
||||
/**
|
||||
* Require Options Services
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-options.php';
|
||||
|
||||
/**
|
||||
* Require Recaptcha Services Class
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-recaptcha.php';
|
||||
|
||||
/**
|
||||
* Require Services Class
|
||||
* TODO: need to rename for meaningful idea.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-passwords.php';
|
||||
|
||||
/**
|
||||
* The class responsible for subscribe services
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-subscribe.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining all actions that occur in the admin area.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-assets.php';
|
||||
|
||||
/**
|
||||
* The class responsible for caching service
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-cache.php';
|
||||
|
||||
/**
|
||||
* The class responsible for settings
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . '/includes/class-ppw-settings.php';
|
||||
|
||||
/**
|
||||
* The class responsible for sitewide settings
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . '/includes/class-ppw-sitewide-settings.php';
|
||||
|
||||
/**
|
||||
* The class responsible for external settings
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . '/includes/class-ppw-external-settings.php';
|
||||
|
||||
/**
|
||||
* The class responsible for shortcode settings
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . '/includes/class-ppw-partial-protection-settings.php';
|
||||
|
||||
/**
|
||||
* The class responsible for entire site services
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-entire-site.php';
|
||||
|
||||
/**
|
||||
* The class responsible for shortcode service
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-shortcode.php';
|
||||
|
||||
/**
|
||||
* The class responsible for API declaration
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ppw-api.php';
|
||||
|
||||
/**
|
||||
* The class responsible for core functions
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'core/class-ppw-functions.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining all actions that occur in the admin area.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-ppw-admin.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining all actions that occur in the public-facing
|
||||
* side of the site.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-ppw-public.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining all actions that occur in the customizer
|
||||
* side of the site.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-customizer.php';
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-customizer-sitewide.php';
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-customizer-upsell.php';
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-customizer-pcp.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining all addons.
|
||||
*/
|
||||
require_once PPW_DIR_PATH . 'includes/addons/beaver-builder/class-ppw-beaver-loader.php';
|
||||
require_once PPW_DIR_PATH . 'includes/addons/elementor/class-ppw-elementor.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining database functions.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-ppw-db.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining protect category.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-category.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining protect category.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/services/class-ppw-content-protection.php';
|
||||
|
||||
/**
|
||||
* The class responsible for plugin SDK
|
||||
*/
|
||||
if ( is_pro_active_and_valid_license() ) {
|
||||
// Need the load the pro lib first that using for the other add-ons.
|
||||
ppw_core_load_pro_lib();
|
||||
}
|
||||
|
||||
$this->loader = new PPW_Loader();
|
||||
|
||||
$pro_version = ppw_get_pro_data_version();
|
||||
if ( $pro_version && version_compare( $pro_version, '1.3.2', '<' ) ) {
|
||||
if ( function_exists( 'wp_get_theme' ) ) {
|
||||
$curr_theme = wp_get_theme();
|
||||
$theme_name = $curr_theme->get( 'Name' );
|
||||
if ( method_exists( $curr_theme, 'get' )
|
||||
&& in_array( $theme_name, array( 'Edubin', 'StoreVilla' ) ) ) {
|
||||
require_once( ABSPATH . WPINC . '/class-wp-customize-section.php' );
|
||||
}
|
||||
}
|
||||
|
||||
require_once( ABSPATH . WPINC . '/class-wp-customize-control.php' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the locale for this plugin for internationalization.
|
||||
*
|
||||
* Uses the Password_Protect_Page_i18n class in order to set the domain and to register the hook
|
||||
* with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*/
|
||||
private function set_locale() {
|
||||
|
||||
$plugin_i18n = new PPW_i18n();
|
||||
|
||||
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all of the hooks related to the admin area functionality
|
||||
* of the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*/
|
||||
private function define_admin_hooks() {
|
||||
|
||||
$plugin_admin = new PPW_Admin( $this->get_plugin_name(), $this->get_version() );
|
||||
PPW_Customizer_Service::get_instance();
|
||||
PPW_Customizer_Sitewide::register_themes();
|
||||
PPW_Recaptcha::get_instance()->register();
|
||||
|
||||
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_assets' );
|
||||
$this->loader->add_action( 'admin_menu', $plugin_admin, 'ppw_add_menu', 10 );
|
||||
$this->loader->add_action( 'admin_notices', $plugin_admin, 'handle_admin_notices', 10 );
|
||||
|
||||
$this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'ppw_free_add_custom_meta_box_to_edit_page' );
|
||||
$this->loader->add_action( 'login_form_ppw_postpass', $plugin_admin, 'ppw_handle_enter_password' );
|
||||
|
||||
// Hook to handle default action WordPress which use our plugin.
|
||||
$this->loader->add_action( 'login_form_postpass', $plugin_admin, 'ppw_handle_enter_password_for_default_action' );
|
||||
|
||||
$this->loader->add_action( 'template_redirect', $plugin_admin, 'ppw_render_form_entire_site' );
|
||||
$this->loader->add_action( 'ppw_redirect_after_enter_password', $plugin_admin, 'ppw_handle_redirect_after_enter_password' );
|
||||
$this->loader->add_action( 'admin_init', $plugin_admin, 'handle_admin_init' );
|
||||
|
||||
$this->load_base();
|
||||
|
||||
if ( ! is_pro_active_and_valid_license() ) {
|
||||
PPW_Customizer_Sitewide::get_instance()->register_sitewide_form();
|
||||
PPW_Customizer_Upsell::get_instance();
|
||||
|
||||
$this->loader->add_action( 'wp_ajax_ppw_free_set_password', $plugin_admin, 'ppw_free_set_password' );
|
||||
$this->loader->add_filter( 'ppwp_customize_password_form', $plugin_admin, 'render_custom_below_description' );
|
||||
$this->loader->add_action( 'wp_ajax_ppw_free_update_general_settings', $plugin_admin, 'ppw_free_update_general_settings' );
|
||||
$this->loader->add_action( 'wp_ajax_ppw_free_update_entire_site_settings', $plugin_admin, 'ppw_free_update_entire_site_settings' );
|
||||
$this->loader->add_action( 'admin_init', $plugin_admin, 'handle_admin_init_when_pro_is_not_activate' );
|
||||
|
||||
$this->loader->add_action( 'ppw_render_content_general', $plugin_admin, 'ppw_free_render_content_general', 10 );
|
||||
$this->loader->add_action( 'ppw_render_content_entire_site', $plugin_admin, 'ppw_free_render_content_entire_site', 11 );
|
||||
|
||||
$this->loader->add_filter( 'post_password_required', $plugin_admin, 'ppw_handle_post_password_required', 10, 2 );
|
||||
$this->loader->add_filter( PPW_Constants::HOOK_CUSTOM_TAB, $plugin_admin, 'ppw_handle_custom_tab', 50 );
|
||||
$this->loader->add_filter( PPW_Constants::HOOK_ADD_NEW_TAB, $plugin_admin, 'ppw_handle_add_new_tab', 50 );
|
||||
$this->loader->add_filter( PPW_Constants::HOOK_CUSTOM_TAB, $plugin_admin, 'ppw_handle_hide_shortcode_content', 50 );
|
||||
$this->loader->add_filter( PPW_Constants::HOOK_ADD_NEW_TAB, $plugin_admin, 'ppw_handle_hide_shortcode_tab', 50 );
|
||||
|
||||
$this->loader->add_action( 'ppw_render_sitewide_content_general', $plugin_admin, 'ppw_free_render_content_entire_site', 10 );
|
||||
// Testing only the new feature that applied for free only.
|
||||
$this->loader->add_shortcode( 'ppw-content-protect', $plugin_admin, 'handle_content_protect_short_code' );
|
||||
|
||||
$this->loader->add_action( 'post_row_actions', $plugin_admin, 'ppw_custom_row_action', 10, 2 );
|
||||
$this->loader->add_action( 'page_row_actions', $plugin_admin, 'ppw_custom_row_action', 10, 2 );
|
||||
$this->loader->add_action( 'wp_ajax_ppw_update_post_status', $plugin_admin, 'handle_update_post_status' );
|
||||
|
||||
$post_types = array( 'post', 'page' );
|
||||
foreach ( $post_types as $post_type ) {
|
||||
$this->loader->add_filter( 'manage_' . $post_type . '_posts_columns', $plugin_admin, 'add_custom_column' );
|
||||
$this->loader->add_action( 'manage_' . $post_type . '_posts_custom_column', $plugin_admin, 'render_content_custom_column', 10, 2 );
|
||||
}
|
||||
PPW_Category_Service::get_instance()->register( false );
|
||||
} else {
|
||||
$this->loader->add_action( 'plugins_loaded', $plugin_admin, 'handle_plugin_loaded' );
|
||||
$this->loader->add_action( 'admin_init', $plugin_admin, 'update_column_for_ppwp_pro' );
|
||||
PPW_Category_Service::get_instance()->register( true );
|
||||
}
|
||||
PPW_Customizer_Sitewide::get_instance()->register_sitewide_style();
|
||||
$this->loader->add_action( 'wp_ajax_ppw_free_update_misc_settings', $plugin_admin, 'ppw_free_update_misc_settings' );
|
||||
$this->loader->add_action( 'wp_ajax_ppw_free_update_category_settings', $plugin_admin, 'ppw_free_update_category_settings' );
|
||||
$this->loader->add_action( 'wp_ajax_ppw_free_update_shortcode_settings', $plugin_admin, 'ppw_free_update_shortcode_settings' );
|
||||
$this->loader->add_action( 'wp_ajax_ppw_free_update_external_settings', $plugin_admin, 'ppw_free_update_external_settings' );
|
||||
$this->loader->add_action( 'wp_ajax_ppw_free_restore_wp_passwords', $plugin_admin, 'ppw_free_restore_wp_passwords' );
|
||||
$this->loader->add_action( 'ppw_render_content_shortcodes', $plugin_admin, 'ppw_free_render_content_shortcodes', 11 );
|
||||
$this->loader->add_action( 'ppw_render_content_master_passwords', $plugin_admin, 'ppw_free_render_content_master_passwords', 11 );
|
||||
$this->loader->add_action( 'ppw_render_content_misc', $plugin_admin, 'ppw_free_render_content_misc', 11 );
|
||||
$this->loader->add_action( 'ppw_render_content_troubleshooting', $plugin_admin, 'ppw_free_render_content_troubleshooting', 11 );
|
||||
$this->loader->add_action( PPW_Constants::HOOK_RESTRICT_CONTENT_AFTER_VALID_PWD, $plugin_admin, 'set_postpass_cookie_to_prevent_cache', 10, 2 );
|
||||
$this->loader->add_action( 'rest_api_init', $plugin_admin, 'rest_api_init', 10, 2 );
|
||||
$this->loader->add_filter( 'ppw_content_shortcode_source', $plugin_admin, 'handle_content_shortcode_for_multiple_pages', 11, 3 );
|
||||
PPW_Beaver_Loader::get_instance();
|
||||
$this->loader->add_action( 'wp_ajax_ppw_free_subscribe_request', $plugin_admin, 'handle_subscribe_request' );
|
||||
$this->loader->add_action( 'ppw_render_pcp_content_general', $plugin_admin, 'ppw_free_render_content_pcp_general_tab', 10 );
|
||||
$this->loader->add_action( 'ppw_render_external_content_recaptcha', $plugin_admin, 'ppw_free_render_content_external_recaptcha', 10 );
|
||||
$this->loader->add_action( 'ppw_render_external_content_configuration', $plugin_admin, 'ppw_free_render_content_external_configuration', 10 );
|
||||
$this->loader->add_action( 'plugin_row_meta', $plugin_admin, 'register_plugins_links', 10, 2 );
|
||||
$this->loader->add_action( 'ppwp_render_sitewide_countdown', $plugin_admin, 'ppw_sitewide_countdown' );
|
||||
$this->loader->add_action( 'ppwp_sitewide_hide_password_form', $plugin_admin, 'ppw_sitewide_hide_password_form' );
|
||||
$this->loader->add_action( 'ppwp_countdown_timer_styles', $plugin_admin, 'register_countdown_timer_style' );
|
||||
$this->loader->add_filter( 'register_post_type_args', $plugin_admin, 'ppwp_unset_rest_routes', 99, 2 );
|
||||
$this->loader->add_filter( 'plugin_action_links_' . PPW_PLUGIN_BASE_NAME, $plugin_admin, 'handle_plugin_links', 30 );
|
||||
$this->loader->add_filter( 'ppwp_customizer_custom_fields', $plugin_admin, 'ppw_customizer_custom_fields', 11, 2 );
|
||||
|
||||
PPW_Elementor::get_instance( $this->loader );
|
||||
PPW_Customizer_PCP::get_instance()->register();
|
||||
PPW_Content_Protection::get_instance()->register();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all of the hooks related to the public-facing functionality
|
||||
* of the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*/
|
||||
private function define_public_hooks() {
|
||||
|
||||
$plugin_public = new PPW_Public( $this->get_plugin_name(), $this->get_version() );
|
||||
|
||||
$this->loader->add_action( 'template_redirect', $plugin_public, 'handle_access_link', - 10 );
|
||||
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_assets' );
|
||||
$this->loader->add_filter( 'the_content', $plugin_public, 'ppw_the_content', 99999 );
|
||||
$this->loader->add_filter( 'ppw_cookie_expire', $plugin_public, 'set_cookie_time', 10 );
|
||||
$this->loader->add_filter( 'ppw_sitewide_cookie_expiration', $plugin_public, 'set_cookie_time', 10 );
|
||||
$this->loader->add_filter( 'ppw_sitewide_form_action', $plugin_public, 'set_sitewide_form_action', 10 );
|
||||
|
||||
$this->loader->add_action( 'wp_ajax_nopriv_ppw_validate_password', $plugin_public, 'ppw_validate_password' );
|
||||
$this->loader->add_action( 'wp_ajax_ppw_validate_password', $plugin_public, 'ppw_validate_password' );
|
||||
$this->loader->add_filter( 'et_builder_load_actions', $plugin_public, 'add_action_to_divi' );
|
||||
|
||||
|
||||
/**
|
||||
* The hook to render our password form
|
||||
*/
|
||||
$this->loader->add_filter( 'the_password_form', $plugin_public, 'ppw_the_password_form', 99999999 );
|
||||
|
||||
// Register ppwp_content_protector shortcode with WordPress.
|
||||
$this->loader->add_action( 'init', $plugin_public, 'register_shortcodes' );
|
||||
// Add hook to handle feature "Hide Protected Content".
|
||||
$this->loader->add_filter( 'posts_where_paged', $plugin_public, 'handle_hide_post_protected', 10, 2 );
|
||||
$this->loader->add_filter( 'widget_posts_args', $plugin_public, 'handle_hide_post_protected_recent_post', 10, 1 );
|
||||
$this->loader->add_filter( 'get_next_post_where', $plugin_public, 'handle_hide_post_protected_next_and_previous', 10, 1 );
|
||||
$this->loader->add_filter( 'get_previous_post_where', $plugin_public, 'handle_hide_post_protected_next_and_previous', 10, 1 );
|
||||
$this->loader->add_filter( 'get_pages', $plugin_public, 'handle_hide_page_protected', 10, 2 );
|
||||
$this->loader->add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', $plugin_public, 'handle_hide_page_protected_yoast_seo_sitemaps', 10, 1 );
|
||||
|
||||
$this->loader->add_filter( 'ppwp_ppf_action_url', $plugin_public, 'ppw_core_get_ppf_action_url' );
|
||||
$this->loader->add_action( 'wp', $plugin_public, 'ppw_core_validate_login', 5 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the loader to execute all of the hooks with WordPress.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function run() {
|
||||
$this->loader->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the plugin used to uniquely identify it within the context of
|
||||
* WordPress and to define internationalization functionality.
|
||||
*
|
||||
* @return string The name of the plugin.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function get_plugin_name() {
|
||||
return $this->plugin_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The reference to the class that orchestrates the hooks with the plugin.
|
||||
*
|
||||
* @return PPW_Loader Orchestrates the hooks of the plugin.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function get_loader() {
|
||||
return $this->loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the version number of the plugin.
|
||||
*
|
||||
* @return string The version number of the plugin.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function get_version() {
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load base classes
|
||||
*/
|
||||
private function load_base() {
|
||||
$core_dir = PPW_DIR_PATH . 'core/base';
|
||||
require_once "$core_dir/class-ppw-module.php";
|
||||
require_once "$core_dir/class-ppw-background-task.php";
|
||||
require_once PPW_DIR_PATH . 'includes/services/class-ppw-migration.php';
|
||||
require_once "$core_dir/class-ppw-background-task-manager.php";
|
||||
require_once "$core_dir/class-ppw-data-migration-manager.php";
|
||||
|
||||
require_once PPW_DIR_PATH . 'includes/services/class-ppw-migrations.php';
|
||||
require_once PPW_DIR_PATH . 'includes/services/class-ppw-migration-manager.php';
|
||||
require_once PPW_DIR_PATH . 'includes/services/class-ppw-password-recovery.php';
|
||||
require_once PPW_DIR_PATH . 'includes/services/class-ppw-password-recovery-manager.php';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
body.ppwp-sitewide-protection {
|
||||
background: #2a2c2e url("<?php echo esc_url( ppw_get_background_image( 'sw-default1.jpg' ) ); ?>") no-repeat center/cover !important;
|
||||
}
|
||||
|
||||
.pda-form-login {
|
||||
width: 50%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
margin: 0 0 0 auto;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.ppwp-countdown-container {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
right: 2px;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.pda-form-login a.ppw-swp-logo {
|
||||
top: 22%;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.pda-form-login form {
|
||||
position: absolute;
|
||||
width: 350px;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
top: 50%;
|
||||
padding: 3rem;
|
||||
background: #0404047a;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.pda-form-login .input_wp_protect_password,
|
||||
.pda-form-login .button-login {
|
||||
width: 100%;
|
||||
padding: .8rem;
|
||||
border: 1px solid #001428;
|
||||
outline: 0;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.pda-form-login .input_wp_protect_password {
|
||||
background: #acb2c9;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.pda-form-login .button-login {
|
||||
text-transform: uppercase;
|
||||
font-weight: 700;
|
||||
background: #001428;
|
||||
border-color: #fff;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
body.ppwp-sitewide-protection {
|
||||
background: #2a2c2e url("<?php echo esc_url( ppw_get_background_image( 'sw-default2.jpg' ) ); ?>") no-repeat center/cover !important;
|
||||
}
|
||||
|
||||
.pda-form-login {
|
||||
width: 50%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
left: 0;
|
||||
margin: 0 0 0 auto;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.ppwp-countdown-container {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
right: 2px;
|
||||
width: 50%;
|
||||
margin: 0 0 0 auto;
|
||||
}
|
||||
|
||||
.pda-form-login form {
|
||||
max-width: 350px;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
position: relative;
|
||||
padding: 2rem;
|
||||
overflow: hidden;
|
||||
background: #111;
|
||||
border-radius: 0.4em;
|
||||
border: 1px solid #191919;
|
||||
box-shadow: 1px 1px 78px #171717;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.pda-form-login a.ppw-swp-logo {
|
||||
top: 26%;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.pda-form-login form:before {
|
||||
content: "";
|
||||
width: 8px;
|
||||
height: 5px;
|
||||
position: absolute;
|
||||
left: 34%;
|
||||
top: -7px;
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 0 6px 4px #fff;
|
||||
}
|
||||
|
||||
.pda-form-login form:after {
|
||||
content: "";
|
||||
width: 400px;
|
||||
height: 200px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 35px;
|
||||
transform: rotate(75deg);
|
||||
background: linear-gradient(50deg, rgba(255, 255, 255, 0.15), transparent);
|
||||
opacity: .4;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.pda-form-login .input_wp_protect_password {
|
||||
padding: .8rem;
|
||||
background: linear-gradient(#1f2124, #27292c);
|
||||
border: 1px solid #000;
|
||||
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1);
|
||||
border-radius: 3px;
|
||||
color: #fff;
|
||||
padding-right: 2.5rem;
|
||||
}
|
||||
|
||||
.pda-form-login .input_wp_protect_password:focus {
|
||||
box-shadow: inset 0 0 2px #000;
|
||||
background: #494d54;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.pda-form-login .button-login {
|
||||
width: 100%;
|
||||
border: 1px solid rgba(0, 0, 0, 0.4);
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), inset 0 10px 10px rgba(255, 255, 255, 0.1);
|
||||
border-radius: 3px;
|
||||
background: #218dd6;
|
||||
cursor: pointer;
|
||||
font-weight: 700;
|
||||
font-size: 15px;
|
||||
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.8);
|
||||
margin-top: 1rem;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
body.ppwp-sitewide-protection {
|
||||
background: #2a2c2e url("<?php echo esc_url( ppw_get_background_image( 'sw-default3.jpg' ) ); ?>") no-repeat center/cover !important;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.pda-form-login {
|
||||
width: 50%;
|
||||
background: #ffffffc4;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
box-shadow: 0 1px 13px #ECEBEB;
|
||||
left: 0;
|
||||
margin: 0;
|
||||
padding-top:0;
|
||||
}
|
||||
|
||||
.ppwp-countdown-container {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 50%;
|
||||
margin: 0 0 0 auto;
|
||||
}
|
||||
|
||||
.pda-form-login a.ppw-swp-logo {
|
||||
top: 32%;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.pda-form-login form {
|
||||
position: absolute;
|
||||
max-width: 350px;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
background: transparent;
|
||||
box-shadow: 0 0 black;
|
||||
}
|
||||
|
||||
.pda-form-login .input_wp_protect_password {
|
||||
width: 100%;
|
||||
font-size: 1rem;
|
||||
outline: 0;
|
||||
border-radius: 30px;
|
||||
border: 2px solid #d0cece;
|
||||
padding: 1rem 3.5rem 1rem 1.5rem;
|
||||
background: white;
|
||||
}
|
||||
.pda-form-login .button-login {
|
||||
margin-top: 1rem;
|
||||
text-transform: uppercase;
|
||||
font-weight: 700;
|
||||
color: #fff;
|
||||
border-color: #cac8c7;
|
||||
border-radius: 30px;
|
||||
width: 40%;
|
||||
text-align: center;
|
||||
padding: .8rem;
|
||||
background: #7d7974;
|
||||
box-shadow: 2px 4px 1px #cac8c7;
|
||||
}
|
||||
|
After Width: | Height: | Size: 230 KiB |
|
After Width: | Height: | Size: 2.1 MiB |
|
After Width: | Height: | Size: 459 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 45 KiB |
@@ -0,0 +1,4 @@
|
||||
.datetime .customize-control-error-message {
|
||||
color: red;
|
||||
display: none;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
( function( $, api ) {
|
||||
|
||||
api.controlConstructor['datetime'] = api.Control.extend( {
|
||||
|
||||
ready: function() {
|
||||
var control = this;
|
||||
this.container.on( 'change', 'input[type="datetime-local"]', function() {
|
||||
if (control.params.id === 'ppwp_sitewide_start_time' && this.value ) {
|
||||
var endTime = document.getElementById("datetime-ppwp_sitewide_end_time");
|
||||
endTime.min = this.value;
|
||||
}
|
||||
if (control.params.id === 'ppwp_sitewide_start_time' && !this.value ) {
|
||||
var endTime = document.getElementById("datetime-ppwp_sitewide_end_time");
|
||||
endTime.min = this.min;
|
||||
}
|
||||
if (control.params.id === 'ppwp_sitewide_end_time' ) {
|
||||
document.getElementById('datetime-ppwp_sitewide_end_time-error-message').style.display = 'none';
|
||||
var startTime = document.getElementById("datetime-ppwp_sitewide_start_time").value;
|
||||
var countDownDateStart = new Date(startTime).getTime();
|
||||
var countDownDateEnd = new Date(this.value).getTime();
|
||||
if ( countDownDateStart > countDownDateEnd ) {
|
||||
document.getElementById('datetime-ppwp_sitewide_end_time-error-message').style.display = 'block';
|
||||
}
|
||||
}
|
||||
value = this.value;
|
||||
control.setting.set( value );
|
||||
} );
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
} )( jQuery, wp.customize );
|
||||
@@ -0,0 +1,40 @@
|
||||
.control-title--wrapper span.customize-control-title {
|
||||
margin: 0px -12px;
|
||||
border: 1px solid #ddd;
|
||||
padding: 13px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 2px;
|
||||
line-height: 1;
|
||||
text-transform: uppercase;
|
||||
color: #555;
|
||||
background-color: #fff;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
#accordion-panel-ppwp {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
#accordion-panel-ppwp h3 {
|
||||
border-top: 1px solid #ddd;
|
||||
}
|
||||
|
||||
#accordion-section-ppwp_upsell {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
#accordion-section-ppwp_upsell .ppwp-accordion-section-title {
|
||||
color: #f78935!important;
|
||||
border-left-color: #f78935!important;
|
||||
}
|
||||
|
||||
#accordion-section-ppwp_upsell .ppwp-accordion-section-title a {
|
||||
color: #f78935!important;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
#accordion-section-ppwp_upsell .accordion-section-title:after {
|
||||
color: #f78935!important;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
.customize-control-toggle .toggle--wrapper {
|
||||
display: -webkit-box;
|
||||
display: -webkit-flex;
|
||||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
-webkit-box-direction: normal;
|
||||
-webkit-box-orient: horizontal;
|
||||
-webkit-box-pack: start;
|
||||
-webkit-flex-direction: row;
|
||||
-ms-flex-direction: row;
|
||||
-ms-flex-pack: start;
|
||||
-webkit-justify-content: flex-start;
|
||||
justify-content: flex-start;
|
||||
margin-bottom: 10px;
|
||||
align-items: baseline;
|
||||
}
|
||||
|
||||
.customize-control-toggle .toggle--wrapper .customize-control-title {
|
||||
font-weight: 600;
|
||||
margin-bottom: 0px;
|
||||
vertical-align: middle;
|
||||
-webkit-box-flex: 2;
|
||||
-webkit-flex: 2 0 0;
|
||||
-ms-flex: 2 0 0;
|
||||
flex: 2 0 0;
|
||||
}
|
||||
|
||||
.customize-control-toggle .toggle--wrapper input[type=checkbox] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.customize-control-toggle {
|
||||
margin-bottom: 0
|
||||
}
|
||||
|
||||
.customize-control-toggle .toggle--wrapper label {
|
||||
background-color: #555d66;
|
||||
border-radius: 14px;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
height: 20px;
|
||||
outline: none;
|
||||
position: relative;
|
||||
right: 0px;
|
||||
top: 2px;
|
||||
-webkit-transition: background 0.2s ease;
|
||||
transition: background 0.2s ease;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
width: 34px;
|
||||
}
|
||||
|
||||
.customize-control-toggle .toggle--wrapper label::after,
|
||||
.customize-control-toggle .toggle--wrapper label::before {
|
||||
content: "";
|
||||
display: block;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.customize-control-toggle .toggle--wrapper label::after {
|
||||
border: 2px solid #555d66;
|
||||
border-radius: 50%;
|
||||
box-sizing: border-box;
|
||||
height: 12px;
|
||||
left: 4px;
|
||||
top: 4px;
|
||||
-webkit-transition: background 0.2s ease, -webkit-transform 0.2s ease;
|
||||
transition: background 0.2s ease, -webkit-transform 0.2s ease;
|
||||
transition: transform 0.2s ease, background 0.2s ease;
|
||||
transition: transform 0.2s ease, background 0.2s ease, -webkit-transform 0.2s ease;
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
.customize-control-toggle .toggle--wrapper label::before {
|
||||
background-color: #eee;
|
||||
border-radius: 60px;
|
||||
bottom: 2px;
|
||||
left: 2px;
|
||||
right: 2px;
|
||||
top: 2px;
|
||||
-webkit-transition: background 0.2s ease;
|
||||
transition: background 0.2s ease;
|
||||
}
|
||||
|
||||
.customize-control-toggle .toggle--wrapper input[type=checkbox]:checked + label {
|
||||
background-color: #f78935;
|
||||
}
|
||||
|
||||
.customize-control-toggle .toggle--wrapper input[type=checkbox]:checked + label::after {
|
||||
background-color: #f78935;
|
||||
border: 2px solid #fff;
|
||||
-webkit-transform: translateX(14px);
|
||||
-ms-transform: translateX(14px);
|
||||
transform: translateX(14px);
|
||||
}
|
||||
|
||||
.customize-control-toggle .toggle--wrapper input[type=checkbox]:checked + label::before {
|
||||
background-color: #f78935;
|
||||
}
|
||||
|
||||
.customize-control-toggle:hover .toggle--wrapper label::before {
|
||||
background-color: #fdefe4;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
( function( $, api ) {
|
||||
|
||||
api.controlConstructor['toggle'] = api.Control.extend( {
|
||||
|
||||
ready: function() {
|
||||
var control = this;
|
||||
|
||||
this.container.on( 'change', 'input:checkbox', function() {
|
||||
value = this.checked ? true : false;
|
||||
control.setting.set( value );
|
||||
} );
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
} )( jQuery, wp.customize );
|
||||
@@ -0,0 +1,12 @@
|
||||
( function( $, api ) {
|
||||
api.sectionConstructor['ppwp-upsell-section'] = api.Section.extend( {
|
||||
|
||||
// No events for this type of section.
|
||||
attachEvents: function () {},
|
||||
|
||||
// Always make the section active.
|
||||
isContextuallyActive: function () {
|
||||
return true;
|
||||
}
|
||||
} );
|
||||
} )( jQuery, wp.customize );
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( class_exists( 'WP_Customize_Section' ) && ! class_exists( 'PPW_Customize_Link_Section' ) ) {
|
||||
|
||||
/**
|
||||
* PPW_Customize_Link_Section Initial setup
|
||||
*/
|
||||
class PPW_Customize_Link_Section extends WP_Customize_Section {
|
||||
public $type = 'ppwp-upsell-section';
|
||||
public $ppwp_url = '';
|
||||
public $ppwp_text = '';
|
||||
public $id = '';
|
||||
|
||||
public function json() {
|
||||
$json = parent::json();
|
||||
$json['ppwp_text'] = $this->ppwp_text;
|
||||
$json['ppwp_url'] = esc_url( $this->ppwp_url );
|
||||
$json['id'] = $this->id;
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
protected function render_template() {
|
||||
?>
|
||||
<li id="accordion-section-{{ data.id }}"
|
||||
class="ppwp-accordion-section accordion-section control-section control-panel control-panel-default">
|
||||
<h3 class="ppwp-accordion-section-title accordion-section-title"><a href="{{{ data.ppwp_url }}}"
|
||||
target="_blank">{{ data.ppwp_text
|
||||
}}</a></h3>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* datetime Customizer Control
|
||||
*/
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Exit if WP_Customize_Control does not exsist.
|
||||
if ( ! class_exists( 'WP_Customize_Control' ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is for the datetime control in the Customizer.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
|
||||
class PPW_Datetime_Control extends WP_Customize_Control {
|
||||
|
||||
/**
|
||||
* The type of customize control.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.3.4
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'datetime';
|
||||
|
||||
/**
|
||||
* Enqueue scripts and styles.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue() {
|
||||
wp_enqueue_style( 'ppw-designer-datetime-control-styles', PPW_DIR_URL . 'includes/customizers/assets/ppw-datetime.css', false, PPW_VERSION, 'all' );
|
||||
wp_enqueue_script( 'ppw-designer-datetime-control-scripts', PPW_DIR_URL . 'includes/customizers/assets/ppw-datetime.js', array( 'jquery' ), PPW_VERSION, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom parameters to pass to the JS via JSON.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function to_json() {
|
||||
parent::to_json();
|
||||
|
||||
// The setting value.
|
||||
$this->json['id'] = $this->id;
|
||||
$this->json['value'] = $this->value();
|
||||
$this->json['min'] = date('Y-m-d\TH:i', current_time( 'timestamp' ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't render the content via PHP. This control is handled with a JS template.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function render_content() {}
|
||||
|
||||
/**
|
||||
* An Underscore (JS) template for this control's content.
|
||||
*
|
||||
* Class variables for this control class are available in the `data` JS object;
|
||||
* export custom variables by overriding {@see WP_Customize_Control::to_json()}.
|
||||
*
|
||||
* @see WP_Customize_Control::print_template()
|
||||
*
|
||||
* @access protected
|
||||
* @since 1.3.4
|
||||
* @return void
|
||||
*/
|
||||
protected function content_template() {
|
||||
?>
|
||||
<label class="datetime">
|
||||
<div class="datetime--wrapper">
|
||||
<# if ( data.label ) { #>
|
||||
<span class="customize-control-title">{{ data.label }}</span>
|
||||
<# } #>
|
||||
<# if ( data.description ) { #>
|
||||
<span class="customize-control-description"><span>Note:</span> {{ data.description }}</span>
|
||||
<# } #>
|
||||
<input type="datetime-local" id="datetime-{{ data.id }}" name="datetime" min="{{ data.min }}" value="{{ data.value }}">
|
||||
<label for="datetime-{{ data.id }}" class="datetime-label"></label>
|
||||
</div>
|
||||
|
||||
<span id="datetime-{{ data.id }}-error-message" class="customize-control-error-message">Input wrong value.</span>
|
||||
</label>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
<?php
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Exit if WP_Customize_Control does not exsist.
|
||||
if ( ! class_exists( 'WP_Customize_Control' ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
class PPW_Presets_Control extends WP_Customize_Control {
|
||||
/**
|
||||
* @var string Control type
|
||||
*/
|
||||
public $type = 'ppw-presets';
|
||||
|
||||
/**
|
||||
* Render the content on the theme customizer page.
|
||||
*/
|
||||
public function render_content() {
|
||||
if ( empty( $this->choices ) ) {
|
||||
return;
|
||||
}
|
||||
$name = 'password-protect-page_preset-' . $this->id; ?>
|
||||
|
||||
<span class="customize-control-title">
|
||||
<?php echo esc_attr( $this->label ); ?>
|
||||
<?php if ( ! empty( $this->description ) ) : ?>
|
||||
<span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
|
||||
<div id="input_<?php echo esc_attr( $this->id ); ?>" class="image">
|
||||
<?php foreach ( $this->choices as $val ) : ?>
|
||||
<div class="password-protect-page_thumbnail">
|
||||
<input class="image-select" type="radio"
|
||||
value="<?php echo esc_attr( $val['id'] ); ?>"
|
||||
id="<?php echo esc_attr($this->id . $val['id']); ?>"
|
||||
name="<?php echo esc_attr( $name ); ?>" <?php checked( $this->value(), $val['id'] ); ?> />
|
||||
<label for="<?php echo esc_attr($this->id . $val['id']); ?>">
|
||||
<div class="password-protect-page_thumbnail_img">
|
||||
<img src="<?php echo esc_url($val['thumbnail']); ?>" alt="<?php echo esc_attr( $val['id'] ); ?>"
|
||||
title="<?php echo esc_attr( $val['id'] ); ?>">
|
||||
</div>
|
||||
<h3><?php echo esc_html( $val['name'] ) ?></h3>
|
||||
</label>
|
||||
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<input name='presets_hidden' type="hidden" <?php $this->link(); ?> value="<?php echo esc_attr( $this->value() ); ?>"/>
|
||||
<?php }
|
||||
}
|
||||
|
||||
function ppw_presets_control_css() {
|
||||
?>
|
||||
<style>
|
||||
.customize-control-ppw-presets .image.ui-buttonset input[type=radio] {
|
||||
height: auto;
|
||||
}
|
||||
.customize-control-ppw-presets .image.ui-buttonset label {
|
||||
display: inline-block;
|
||||
margin-right: 5px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.customize-control-ppw-presets .image.ui-buttonset label.ui-state-active {
|
||||
background: none;
|
||||
}
|
||||
.customize-control-ppw-presets .customize-control-radio-buttonset label {
|
||||
padding: 5px 10px;
|
||||
background: #f7f7f7;
|
||||
border-left: 1px solid #dedede;
|
||||
line-height: 35px;
|
||||
}
|
||||
.customize-control-ppw-presets label img {
|
||||
border: 1px solid #bbb;
|
||||
opacity: 0.5;
|
||||
}
|
||||
#customize-controls .customize-control-ppw-presets label img {
|
||||
max-width: 250px;
|
||||
height: auto;
|
||||
width: 100%;
|
||||
margin-bottom: 0;
|
||||
border: 0;
|
||||
display: block;
|
||||
}
|
||||
.customize-control-ppw-presets label.ui-state-active img {
|
||||
background: #dedede;
|
||||
border-color: #000;
|
||||
opacity: 1;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.customize-control-ppw-presets label.ui-state-hover img {
|
||||
opacity: 0.9;
|
||||
border-color: #999;
|
||||
}
|
||||
.customize-control-radio-buttonset label.ui-corner-left {
|
||||
border-radius: 3px 0 0 3px;
|
||||
border-left: 0;
|
||||
}
|
||||
.customize-control-radio-buttonset label.ui-corner-right {
|
||||
border-radius: 0 3px 3px 0;
|
||||
}
|
||||
#customize-control-ppw_customize_presets_settings input[type=radio]{
|
||||
display: none;
|
||||
}
|
||||
#customize-control-ppw_customize_presets_settings label{
|
||||
display: block;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
#customize-control-ppw_customize_presets_settings .password-protect-page_thumbnail{
|
||||
width: calc(50% - 10px);
|
||||
margin-bottom: 10px;
|
||||
position: relative;
|
||||
border: 5px solid transparent;
|
||||
-webkit-transition:all 0.2s ease-in-out;
|
||||
-moz-transition:all 0.2s ease-in-out;
|
||||
-ms-transition:all 0.2s ease-in-out;
|
||||
transition:all 0.2s ease-in-out;
|
||||
}
|
||||
#customize-control-ppw_customize_presets_settings .password-protect-page_thumbnail:nth-child(odd){
|
||||
float: left;
|
||||
}
|
||||
#customize-control-ppw_customize_presets_settings .password-protect-page_thumbnail:nth-child(even){
|
||||
float: right;
|
||||
}
|
||||
#customize-control-ppw_customize_presets_settings .image:after{
|
||||
content: '';
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
#customize-control-ppw_customize_presets_settings h3{
|
||||
margin: 0;
|
||||
font: 400 14px 'Open Sans', Arial, Helvetica, sans-serif;
|
||||
line-height: 1.1;
|
||||
padding: 3px;
|
||||
text-align: center;
|
||||
background: #eee;
|
||||
color: #777777;
|
||||
}
|
||||
#customize-control-ppw_customize_presets_settings label .password-protect-page_thumbnail_img:after {
|
||||
content: '';
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 50%;
|
||||
background: #ff8935;
|
||||
position: absolute;
|
||||
top: -5px;
|
||||
left: -5px;
|
||||
border-radius: 50%;
|
||||
visibility: hidden;
|
||||
}
|
||||
#customize-control-ppw_customize_presets_settings label .password-protect-page_thumbnail_img:before {
|
||||
height: 6px;
|
||||
width: 3px;
|
||||
-webkit-transform-origin: left top;
|
||||
-moz-transform-origin: left top;
|
||||
-ms-transform-origin: left top;
|
||||
-o-transform-origin: left top;
|
||||
transform-origin: left top;
|
||||
border-right: 3px solid white;
|
||||
border-top: 3px solid white;
|
||||
border-radius: 2.5px !important;
|
||||
content: '';
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
opacity: 0;
|
||||
margin-top: 0px;
|
||||
margin-left: -7px;
|
||||
top: 5px;
|
||||
left: 4px;
|
||||
}
|
||||
#customize-control-ppw_customize_presets_settings .password-protect-page_thumbnail_img{
|
||||
display: block;
|
||||
position: relative;
|
||||
}
|
||||
#customize-control-ppw_customize_presets_settings input[type="radio"]:checked + label .password-protect-page_thumbnail_img:before {
|
||||
-webkit-animation-delay: 100ms;
|
||||
-moz-animation-delay: 100ms;
|
||||
animation-delay: 100ms;
|
||||
-webkit-animation-duration: 1s;
|
||||
-moz-animation-duration: 1s;
|
||||
animation-duration: 1s;
|
||||
-webkit-animation-timing-function: ease;
|
||||
-moz-animation-timing-function: ease;
|
||||
animation-timing-function: ease;
|
||||
-webkit-animation-name: checkmark;
|
||||
-moz-animation-name: checkmark;
|
||||
animation-name: checkmark;
|
||||
-webkit-transform: scaleX(-1) rotate(135deg);
|
||||
-moz-transform: scaleX(-1) rotate(135deg);
|
||||
-ms-transform: scaleX(-1) rotate(135deg);
|
||||
-o-transform: scaleX(-1) rotate(135deg);
|
||||
transform: scaleX(-1) rotate(135deg);
|
||||
-webkit-animation-fill-mode: forwards;
|
||||
-moz-animation-fill-mode: forwards;
|
||||
animation-fill-mode: forwards;
|
||||
z-index: 2;
|
||||
}
|
||||
#customize-control-ppw_customize_presets_settings input[type="radio"]:checked + label .password-protect-page_thumbnail_img:after{
|
||||
visibility: visible;
|
||||
}
|
||||
#customize-control-ppw_customize_presets_settings img{
|
||||
margin-bottom: 0;
|
||||
}
|
||||
#customize-control-ppw_customize_presets_settings input[type="radio"]:checked + label img{
|
||||
opacity: 1;
|
||||
}
|
||||
#customize-control-ppw_customize_presets_settings .password-protect-page_thumbnail:hover{
|
||||
border-color: #ccc;
|
||||
}
|
||||
|
||||
@-webkit-keyframes checkmark {
|
||||
0% {
|
||||
height: 0;
|
||||
width: 0;
|
||||
opacity: 1;
|
||||
}
|
||||
20% {
|
||||
height: 0;
|
||||
width: 5px;
|
||||
opacity: 1;
|
||||
}
|
||||
40% {
|
||||
height: 10px;
|
||||
width: 5px;
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
height: 10px;
|
||||
width: 5px;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
@-moz-keyframes checkmark {
|
||||
0% {
|
||||
height: 0;
|
||||
width: 0;
|
||||
opacity: 1;
|
||||
}
|
||||
20% {
|
||||
height: 0;
|
||||
width: 5px;
|
||||
opacity: 1;
|
||||
}
|
||||
40% {
|
||||
height: 10px;
|
||||
width: 5px;
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
height: 10px;
|
||||
width: 5px;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
@keyframes checkmark {
|
||||
0% {
|
||||
height: 0;
|
||||
width: 0;
|
||||
opacity: 1;
|
||||
}
|
||||
20% {
|
||||
height: 0;
|
||||
width: 5px;
|
||||
opacity: 1;
|
||||
}
|
||||
40% {
|
||||
height: 10px;
|
||||
width: 5px;
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
height: 10px;
|
||||
width: 5px;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
add_action( 'customize_controls_print_styles', 'ppw_presets_control_css' );
|
||||
?>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Exit if WP_Customize_Control does not exsist.
|
||||
if ( ! class_exists( 'WP_Customize_Control' ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
class PPW_Text_Editor_Custom_Control extends WP_Customize_Control {
|
||||
/**
|
||||
* @var string Control type
|
||||
*/
|
||||
public $type = 'editor';
|
||||
|
||||
/**
|
||||
* Render the content on the theme customizer page.
|
||||
*/
|
||||
public function render_content() {
|
||||
$input_id = $this->id;
|
||||
?>
|
||||
<label>
|
||||
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
|
||||
<span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
|
||||
</label>
|
||||
<input type="hidden" <?php echo esc_url( $this->get_link() ); ?> value="<?php echo esc_attr( $this->value() ); ?>">
|
||||
<?php
|
||||
wp_editor( $this->value(), $input_id, array(
|
||||
'textarea_name' => $input_id,
|
||||
'textarea_rows' => 3,
|
||||
) );
|
||||
do_action( 'admin_footer' );
|
||||
do_action( 'admin_print_footer_scripts' );
|
||||
?>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Toggle Customizer Control
|
||||
*/
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Exit if WP_Customize_Control does not exsist.
|
||||
if ( ! class_exists( 'WP_Customize_Control' ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is for the toggle control in the Customizer.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
|
||||
class PPW_Title_Group_Control extends WP_Customize_Control {
|
||||
|
||||
public $type = 'control_title';
|
||||
|
||||
public function enqueue() {
|
||||
wp_enqueue_style( 'control-title-group-styles', PPW_DIR_URL . 'includes/customizers/assets/ppw-title-group-control.css', false, PPW_VERSION, 'all' );
|
||||
}
|
||||
|
||||
public function render_content() {}
|
||||
|
||||
protected function content_template() {
|
||||
?>
|
||||
<div class="control-title--wrapper">
|
||||
<span class="customize-control-title">{{ data.label }}</span>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* Toggle Customizer Control
|
||||
*/
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Exit if WP_Customize_Control does not exsist.
|
||||
if ( ! class_exists( 'WP_Customize_Control' ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is for the toggle control in the Customizer.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
|
||||
class PPW_Toggle_Control extends WP_Customize_Control {
|
||||
|
||||
/**
|
||||
* The type of customize control.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.3.4
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'toggle';
|
||||
|
||||
/**
|
||||
* Enqueue scripts and styles.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue() {
|
||||
wp_enqueue_style( 'ppw-designer-toggle-control-styles', PPW_DIR_URL . 'includes/customizers/assets/ppw-toggle-control.css', false, PPW_VERSION, 'all' );
|
||||
wp_enqueue_script( 'ppw-designer-toggle-control-scripts', PPW_DIR_URL . 'includes/customizers/assets/ppw-toggle-control.js', array( 'jquery' ), PPW_VERSION, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom parameters to pass to the JS via JSON.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function to_json() {
|
||||
parent::to_json();
|
||||
|
||||
// The setting value.
|
||||
$this->json['id'] = $this->id;
|
||||
$this->json['value'] = $this->value();
|
||||
$this->json['link'] = $this->get_link();
|
||||
$this->json['defaultValue'] = $this->setting->default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't render the content via PHP. This control is handled with a JS template.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function render_content() {}
|
||||
|
||||
/**
|
||||
* An Underscore (JS) template for this control's content.
|
||||
*
|
||||
* Class variables for this control class are available in the `data` JS object;
|
||||
* export custom variables by overriding {@see WP_Customize_Control::to_json()}.
|
||||
*
|
||||
* @see WP_Customize_Control::print_template()
|
||||
*
|
||||
* @access protected
|
||||
* @since 1.3.4
|
||||
* @return void
|
||||
*/
|
||||
protected function content_template() {
|
||||
?>
|
||||
<label class="toggle">
|
||||
<div class="toggle--wrapper">
|
||||
|
||||
<# if ( data.label ) { #>
|
||||
<span class="customize-control-title">{{ data.label }}</span>
|
||||
<# } #>
|
||||
|
||||
<input id="toggle-{{ data.id }}" type="checkbox" class="toggle--input" value="{{ data.value }}" {{{ data.link }}} <# if ( data.value ) { #> checked="checked" <# } #> />
|
||||
<label for="toggle-{{ data.id }}" class="toggle--label"></label>
|
||||
</div>
|
||||
|
||||
<# if ( data.description ) { #>
|
||||
<span class="description customize-control-description">{{ data.description }}</span>
|
||||
<# } #>
|
||||
</label>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
||||
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/A5hleyRich/wp-background-processing GPL v2.0
|
||||
*
|
||||
* WP Async Request
|
||||
*
|
||||
* @package WP-Background-Processing
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'WP_Async_Request' ) ) {
|
||||
|
||||
/**
|
||||
* Abstract WP_Async_Request class.
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
abstract class WP_Async_Request {
|
||||
|
||||
/**
|
||||
* Prefix
|
||||
*
|
||||
* (default value: 'wp')
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $prefix = 'wp';
|
||||
|
||||
/**
|
||||
* Action
|
||||
*
|
||||
* (default value: 'async_request')
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $action = 'async_request';
|
||||
|
||||
/**
|
||||
* Identifier
|
||||
*
|
||||
* @var mixed
|
||||
* @access protected
|
||||
*/
|
||||
protected $identifier;
|
||||
|
||||
/**
|
||||
* Data
|
||||
*
|
||||
* (default value: array())
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* Initiate new async request
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->identifier = $this->prefix . '_' . $this->action;
|
||||
|
||||
add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) );
|
||||
add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set data used during the request
|
||||
*
|
||||
* @param array $data Data.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function data( $data ) {
|
||||
$this->data = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the async request
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function dispatch() {
|
||||
$url = add_query_arg( $this->get_query_args(), $this->get_query_url() );
|
||||
$args = $this->get_post_args();
|
||||
|
||||
return wp_remote_post( esc_url_raw( $url ), $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get query args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_query_args() {
|
||||
if ( property_exists( $this, 'query_args' ) ) {
|
||||
return $this->query_args;
|
||||
}
|
||||
|
||||
return array(
|
||||
'action' => $this->identifier,
|
||||
'nonce' => wp_create_nonce( $this->identifier ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get query URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_query_url() {
|
||||
if ( property_exists( $this, 'query_url' ) ) {
|
||||
return $this->query_url;
|
||||
}
|
||||
|
||||
return admin_url( 'admin-ajax.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_post_args() {
|
||||
if ( property_exists( $this, 'post_args' ) ) {
|
||||
return $this->post_args;
|
||||
}
|
||||
|
||||
return array(
|
||||
'timeout' => 0.01,
|
||||
'blocking' => false,
|
||||
'body' => $this->data,
|
||||
'cookies' => $_COOKIE,
|
||||
'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe handle
|
||||
*
|
||||
* Check for correct nonce and pass to handler.
|
||||
*/
|
||||
public function maybe_handle() {
|
||||
// Don't lock up other requests while processing
|
||||
session_write_close();
|
||||
|
||||
check_ajax_referer( $this->identifier, 'nonce' );
|
||||
|
||||
$this->handle();
|
||||
|
||||
wp_die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle
|
||||
*
|
||||
* Override this method to perform any actions required
|
||||
* during the async request.
|
||||
*/
|
||||
abstract protected function handle();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,519 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/A5hleyRich/wp-background-processing GPL v2.0
|
||||
*
|
||||
* WP Background Process
|
||||
*
|
||||
* @package WP-Background-Processing
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'WP_Background_Process' ) ) {
|
||||
|
||||
/**
|
||||
* Abstract WP_Background_Process class.
|
||||
*
|
||||
* @abstract
|
||||
* @extends WP_Async_Request
|
||||
*/
|
||||
abstract class WP_Background_Process extends WP_Async_Request {
|
||||
|
||||
/**
|
||||
* Action
|
||||
*
|
||||
* (default value: 'background_process')
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $action = 'background_process';
|
||||
|
||||
/**
|
||||
* Start time of current process.
|
||||
*
|
||||
* (default value: 0)
|
||||
*
|
||||
* @var int
|
||||
* @access protected
|
||||
*/
|
||||
protected $start_time = 0;
|
||||
|
||||
/**
|
||||
* Cron_hook_identifier
|
||||
*
|
||||
* @var mixed
|
||||
* @access protected
|
||||
*/
|
||||
protected $cron_hook_identifier;
|
||||
|
||||
/**
|
||||
* Cron_interval_identifier
|
||||
*
|
||||
* @var mixed
|
||||
* @access protected
|
||||
*/
|
||||
protected $cron_interval_identifier;
|
||||
|
||||
/**
|
||||
* Initiate new background process
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->cron_hook_identifier = $this->identifier . '_cron';
|
||||
$this->cron_interval_identifier = $this->identifier . '_cron_interval';
|
||||
|
||||
add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) );
|
||||
add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function dispatch() {
|
||||
// Schedule the cron healthcheck.
|
||||
$this->schedule_event();
|
||||
|
||||
// Perform remote post.
|
||||
return parent::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Push to queue
|
||||
*
|
||||
* @param mixed $data Data.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function push_to_queue( $data ) {
|
||||
$this->data[] = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save queue
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function save() {
|
||||
$key = $this->generate_key();
|
||||
|
||||
if ( ! empty( $this->data ) ) {
|
||||
update_site_option( $key, $this->data );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update queue
|
||||
*
|
||||
* @param string $key Key.
|
||||
* @param array $data Data.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function update( $key, $data ) {
|
||||
if ( ! empty( $data ) ) {
|
||||
update_site_option( $key, $data );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete queue
|
||||
*
|
||||
* @param string $key Key.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function delete( $key ) {
|
||||
delete_site_option( $key );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate key
|
||||
*
|
||||
* Generates a unique key based on microtime. Queue items are
|
||||
* given a unique key so that they can be merged upon save.
|
||||
*
|
||||
* @param int $length Length.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generate_key( $length = 64 ) {
|
||||
$unique = md5( microtime() . rand() );
|
||||
$prepend = $this->identifier . '_batch_';
|
||||
|
||||
return substr( $prepend . $unique, 0, $length );
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe process queue
|
||||
*
|
||||
* Checks whether data exists within the queue and that
|
||||
* the process is not already running.
|
||||
*/
|
||||
public function maybe_handle() {
|
||||
// Don't lock up other requests while processing
|
||||
session_write_close();
|
||||
|
||||
if ( $this->is_process_running() ) {
|
||||
// Background process already running.
|
||||
wp_die();
|
||||
}
|
||||
|
||||
if ( $this->is_queue_empty() ) {
|
||||
// No data to process.
|
||||
wp_die();
|
||||
}
|
||||
|
||||
check_ajax_referer( $this->identifier, 'nonce' );
|
||||
|
||||
$this->handle();
|
||||
|
||||
wp_die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is queue empty
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_queue_empty() {
|
||||
global $wpdb;
|
||||
|
||||
$table = $wpdb->options;
|
||||
$column = 'option_name';
|
||||
|
||||
if ( is_multisite() ) {
|
||||
$table = $wpdb->sitemeta;
|
||||
$column = 'meta_key';
|
||||
}
|
||||
|
||||
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
|
||||
|
||||
$count = $wpdb->get_var( // phpcs:ignore -- WPCS: db call ok, cache ok.
|
||||
$wpdb->prepare(
|
||||
"SELECT COUNT(*) FROM {$table} WHERE %1s LIKE %s", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- We don't want to set table name as placeholder and put the $column in quotes.
|
||||
$column,
|
||||
$key
|
||||
)
|
||||
);
|
||||
|
||||
return ( $count > 0 ) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is process running
|
||||
*
|
||||
* Check whether the current process is already running
|
||||
* in a background process.
|
||||
*/
|
||||
protected function is_process_running() {
|
||||
if ( get_site_transient( $this->identifier . '_process_lock' ) ) {
|
||||
// Process already running.
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock process
|
||||
*
|
||||
* Lock the process so that multiple instances can't run simultaneously.
|
||||
* Override if applicable, but the duration should be greater than that
|
||||
* defined in the time_exceeded() method.
|
||||
*/
|
||||
protected function lock_process() {
|
||||
$this->start_time = time(); // Set start time of current process.
|
||||
|
||||
$lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute
|
||||
$lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration );
|
||||
|
||||
set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock process
|
||||
*
|
||||
* Unlock the process so that other instances can spawn.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function unlock_process() {
|
||||
delete_site_transient( $this->identifier . '_process_lock' );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get batch
|
||||
*
|
||||
* @return stdClass Return the first batch from the queue
|
||||
*/
|
||||
protected function get_batch() {
|
||||
global $wpdb;
|
||||
|
||||
$table = $wpdb->options;
|
||||
$column = 'option_name';
|
||||
$key_column = 'option_id';
|
||||
$value_column = 'option_value';
|
||||
|
||||
if ( is_multisite() ) {
|
||||
$table = $wpdb->sitemeta;
|
||||
$column = 'meta_key';
|
||||
$key_column = 'meta_id';
|
||||
$value_column = 'meta_value';
|
||||
}
|
||||
|
||||
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
|
||||
|
||||
$query = $wpdb->get_row( // phpcs:ignore -- WPCS: db call ok, cache ok.
|
||||
$wpdb->prepare(
|
||||
"SELECT * FROM {$table} WHERE %1s LIKE %s ORDER BY %s ASC LIMIT 1", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder -- We don't want to set table name as placeholder and put the $column in quotes.
|
||||
$column,
|
||||
$key,
|
||||
$key_column
|
||||
)
|
||||
);
|
||||
|
||||
$batch = new stdClass();
|
||||
// $batch->key = $query->$column;
|
||||
// $batch->data = maybe_unserialize( $query->$value_column );
|
||||
|
||||
$batch->key = !empty( $query->$column ) ? $query->$column : '';
|
||||
$batch->data = !empty( $query->$value_column ) ? maybe_unserialize( $query->$value_column ) : array();
|
||||
|
||||
return $batch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle
|
||||
*
|
||||
* Pass each queue item to the task handler, while remaining
|
||||
* within server memory and time limit constraints.
|
||||
*/
|
||||
protected function handle() {
|
||||
$this->lock_process();
|
||||
|
||||
do {
|
||||
$batch = $this->get_batch();
|
||||
|
||||
foreach ( $batch->data as $key => $value ) {
|
||||
$task = $this->task( $value );
|
||||
|
||||
if ( false !== $task ) {
|
||||
$batch->data[ $key ] = $task;
|
||||
} else {
|
||||
unset( $batch->data[ $key ] );
|
||||
}
|
||||
|
||||
if ( $this->time_exceeded() || $this->memory_exceeded() ) {
|
||||
// Batch limits reached.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Update or delete current batch.
|
||||
if ( ! empty( $batch->data ) ) {
|
||||
$this->update( $batch->key, $batch->data );
|
||||
} else {
|
||||
$this->delete( $batch->key );
|
||||
}
|
||||
} while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() );
|
||||
|
||||
$this->unlock_process();
|
||||
|
||||
// Start next batch or complete process.
|
||||
if ( ! $this->is_queue_empty() ) {
|
||||
$this->dispatch();
|
||||
} else {
|
||||
$this->complete();
|
||||
}
|
||||
|
||||
wp_die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Memory exceeded
|
||||
*
|
||||
* Ensures the batch process never exceeds 90%
|
||||
* of the maximum WordPress memory.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function memory_exceeded() {
|
||||
$memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory
|
||||
$current_memory = memory_get_usage( true );
|
||||
$return = false;
|
||||
|
||||
if ( $current_memory >= $memory_limit ) {
|
||||
$return = true;
|
||||
}
|
||||
|
||||
return apply_filters( $this->identifier . '_memory_exceeded', $return );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get memory limit
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function get_memory_limit() {
|
||||
if ( function_exists( 'ini_get' ) ) {
|
||||
$memory_limit = ini_get( 'memory_limit' );
|
||||
} else {
|
||||
// Sensible default.
|
||||
$memory_limit = '128M';
|
||||
}
|
||||
|
||||
if ( ! $memory_limit || -1 === intval( $memory_limit ) ) {
|
||||
// Unlimited, set to 32GB.
|
||||
$memory_limit = '32000M';
|
||||
}
|
||||
|
||||
return intval( $memory_limit ) * 1024 * 1024;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time exceeded.
|
||||
*
|
||||
* Ensures the batch never exceeds a sensible time limit.
|
||||
* A timeout limit of 30s is common on shared hosting.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function time_exceeded() {
|
||||
$finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds
|
||||
$return = false;
|
||||
|
||||
if ( time() >= $finish ) {
|
||||
$return = true;
|
||||
}
|
||||
|
||||
return apply_filters( $this->identifier . '_time_exceeded', $return );
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete.
|
||||
*
|
||||
* Override if applicable, but ensure that the below actions are
|
||||
* performed, or, call parent::complete().
|
||||
*/
|
||||
protected function complete() {
|
||||
// Unschedule the cron healthcheck.
|
||||
$this->clear_scheduled_event();
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule cron healthcheck
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $schedules Schedules.
|
||||
* @return mixed
|
||||
*/
|
||||
public function schedule_cron_healthcheck( $schedules ) {
|
||||
$interval = apply_filters( $this->identifier . '_cron_interval', 5 );
|
||||
|
||||
if ( property_exists( $this, 'cron_interval' ) ) {
|
||||
$interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval );
|
||||
}
|
||||
|
||||
// Adds every 5 minutes to the existing schedules.
|
||||
$schedules[ $this->identifier . '_cron_interval' ] = array(
|
||||
'interval' => MINUTE_IN_SECONDS * $interval,
|
||||
'display' => sprintf( __( 'Every %d Minutes', 'elementor' ), $interval ),
|
||||
);
|
||||
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle cron healthcheck
|
||||
*
|
||||
* Restart the background process if not already running
|
||||
* and data exists in the queue.
|
||||
*/
|
||||
public function handle_cron_healthcheck() {
|
||||
if ( $this->is_process_running() ) {
|
||||
// Background process already running.
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( $this->is_queue_empty() ) {
|
||||
// No data to process.
|
||||
$this->clear_scheduled_event();
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->handle();
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule event
|
||||
*/
|
||||
protected function schedule_event() {
|
||||
if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
|
||||
wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear scheduled event
|
||||
*/
|
||||
protected function clear_scheduled_event() {
|
||||
$timestamp = wp_next_scheduled( $this->cron_hook_identifier );
|
||||
|
||||
if ( $timestamp ) {
|
||||
wp_unschedule_event( $timestamp, $this->cron_hook_identifier );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel Process
|
||||
*
|
||||
* Stop processing queue items, clear cronjob and delete batch.
|
||||
*
|
||||
*/
|
||||
public function cancel_process() {
|
||||
if ( ! $this->is_queue_empty() ) {
|
||||
$batch = $this->get_batch();
|
||||
|
||||
$this->delete( $batch->key );
|
||||
|
||||
wp_clear_scheduled_hook( $this->cron_hook_identifier );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Task
|
||||
*
|
||||
* Override this method to perform any actions required on each
|
||||
* queue item. Return the modified item for further processing
|
||||
* in the next pass through. Or, return false to remove the
|
||||
* item from the queue.
|
||||
*
|
||||
* @param mixed $item Queue item to iterate over.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function task( $item );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: gaupoit
|
||||
* Date: 7/24/19
|
||||
* Time: 15:00
|
||||
*/
|
||||
if ( ! class_exists( 'PPW_Asset_Services' ) ) {
|
||||
|
||||
class PPW_Asset_Services {
|
||||
|
||||
/**
|
||||
* Current screen
|
||||
*
|
||||
* @var
|
||||
*/
|
||||
private $screen;
|
||||
|
||||
/**
|
||||
* Page name of current screen
|
||||
* @var string
|
||||
*/
|
||||
private $page;
|
||||
|
||||
/**
|
||||
* Tab name of current screen
|
||||
* @var
|
||||
*/
|
||||
private $tab;
|
||||
|
||||
public function __construct( $screen, $get_params ) {
|
||||
$this->screen = $screen;
|
||||
if ( isset( $get_params['page'] ) ) {
|
||||
$this->page = $get_params['page'];
|
||||
}
|
||||
if ( isset( $get_params['tab'] ) ) {
|
||||
$this->tab = $get_params['tab'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render css and js for entire site tab
|
||||
*/
|
||||
public function load_assets_for_entire_site_tab() {
|
||||
$module = PPW_Constants::ENTIRE_SITE_MODULE;
|
||||
if ( PPW_Constants::MENU_NAME === $this->page && 'entire_site' === $this->tab ) {
|
||||
$this->load_bundle_css( PPW_VERSION );
|
||||
$this->load_js( $module, PPW_VERSION );
|
||||
wp_localize_script(
|
||||
"ppw-$module-js",
|
||||
'ppw_entire_site_data',
|
||||
array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
)
|
||||
);
|
||||
$this->load_select2_lib();
|
||||
$this->load_toastr_lib();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render css & js for sitewide submenu
|
||||
*/
|
||||
public function load_assets_for_entire_site_page() {
|
||||
$module = PPW_Constants::ENTIRE_SITE_MODULE;
|
||||
if ( PPW_Constants::SITEWIDE_PAGE_PREFIX === $this->page && ( 'general' === $this->tab || null === $this->tab ) ) {
|
||||
$this->load_bundle_css( PPW_VERSION );
|
||||
$this->load_js( $module, PPW_VERSION );
|
||||
wp_localize_script(
|
||||
"ppw-$module-js",
|
||||
'ppw_entire_site_data',
|
||||
array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
)
|
||||
);
|
||||
$this->load_select2_lib();
|
||||
$this->load_toastr_lib();
|
||||
}
|
||||
}
|
||||
|
||||
public function load_assets_for_shortcode_page() {
|
||||
if ( PPW_Constants::PCP_PAGE_PREFIX === $this->page && ( 'general' === $this->tab || null === $this->tab ) ) {
|
||||
$this->load_bundle_css( PPW_VERSION );
|
||||
$this->load_toastr_lib();
|
||||
$this->load_shared_lib();
|
||||
}
|
||||
}
|
||||
|
||||
public function load_assets_for_external_page() {
|
||||
if ( PPW_Constants::EXTERNAL_SERVICES_PREFIX === $this->page && ( 'recaptcha' === $this->tab || null === $this->tab ) ) {
|
||||
$this->load_bundle_css( PPW_VERSION );
|
||||
$this->load_toastr_lib();
|
||||
$this->load_shared_lib();
|
||||
|
||||
$module = PPW_Constants::EXTERNAL_SETTINGS_MODULE;
|
||||
$this->load_select2_lib();
|
||||
$this->load_js( $module, PPW_VERSION );
|
||||
wp_localize_script(
|
||||
"ppw-$module-js",
|
||||
'ppw_external_data',
|
||||
array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'home_url' => ppw_core_get_home_url_with_ssl(),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function load_assets_for_external_configuration() {
|
||||
if ( PPW_Constants::EXTERNAL_SERVICES_PREFIX === $this->page && 'configuration' === $this->tab ) {
|
||||
$this->load_bundle_css( PPW_VERSION );
|
||||
$this->load_toastr_lib();
|
||||
$this->load_shared_lib();
|
||||
|
||||
$module = PPW_Constants::EXTERNAL_CONFIGURATION_MODULE;
|
||||
$this->load_select2_lib();
|
||||
$this->load_js( $module, PPW_VERSION );
|
||||
wp_localize_script(
|
||||
"ppw-$module-js",
|
||||
'ppw_external_data',
|
||||
array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'home_url' => ppw_core_get_home_url_with_ssl(),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load assets for shortcode setting.
|
||||
*/
|
||||
public function load_assets_for_shortcode_setting() {
|
||||
$module = PPW_Constants::SHORTCODES_SETTINGS_MODULE;
|
||||
$is_shortcode_tab = PPW_Constants::MENU_NAME === $this->page
|
||||
&& 'shortcodes' === $this->tab;
|
||||
$is_pcp_submenu = PPW_Constants::PCP_PAGE_PREFIX === $this->page
|
||||
&& ( 'general' === $this->tab || null === $this->tab );
|
||||
if ( $is_shortcode_tab || $is_pcp_submenu ) {
|
||||
$this->load_select2_lib();
|
||||
$this->load_js( $module, PPW_VERSION );
|
||||
wp_localize_script(
|
||||
"ppw-$module-js",
|
||||
'ppw_shortcode_data',
|
||||
array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'home_url' => ppw_core_get_home_url_with_ssl(),
|
||||
'nonce' => wp_create_nonce( PPW_Constants::GENERAL_FORM_NONCE ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Partial Protection submenu.
|
||||
*
|
||||
* @param string $page Page name.
|
||||
* @param string $tab Tab name.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_partial_protection_submenu( $page, $tab ) {
|
||||
return PPW_Constants::PCP_PAGE_PREFIX === $page
|
||||
&& ( 'general' === $tab || null === $tab );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render css and js for general tab
|
||||
*/
|
||||
public function load_assets_for_general_tab() {
|
||||
$module = PPW_Constants::GENERAL_SETTINGS_MODULE;
|
||||
if ( PPW_Constants::MENU_NAME === $this->page && ( $module === $this->tab || null === $this->tab ) ) {
|
||||
$this->load_bundle_css( PPW_VERSION );
|
||||
$this->load_js( $module, PPW_VERSION );
|
||||
wp_localize_script(
|
||||
"ppw-$module-js",
|
||||
'ppw_general_data',
|
||||
array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'home_url' => ppw_core_get_home_url_with_ssl(),
|
||||
'nonce' => wp_create_nonce( 'wp_rest' ),
|
||||
)
|
||||
);
|
||||
$this->load_select2_lib();
|
||||
$this->load_toastr_lib();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render css and js for general tab
|
||||
*/
|
||||
public function load_assets_for_misc_tab() {
|
||||
$module = PPW_Constants::MISC_SETTINGS_MODULE;
|
||||
if ( PPW_Constants::MENU_NAME === $this->page && ( $module === $this->tab || null === $this->tab ) ) {
|
||||
$this->load_bundle_css( PPW_VERSION );
|
||||
$this->load_js( $module, PPW_VERSION );
|
||||
wp_localize_script(
|
||||
"ppw-$module-js",
|
||||
'ppw_misc_data',
|
||||
array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'home_url' => ppw_core_get_home_url_with_ssl(),
|
||||
'nonce' => wp_create_nonce( 'wp_rest' ),
|
||||
)
|
||||
);
|
||||
$this->load_select2_lib();
|
||||
$this->load_toastr_lib();
|
||||
|
||||
do_action( PPW_Constants::HOOK_ADVANCED_TAB_LOAD_ASSETS );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render css and js for general tab
|
||||
*/
|
||||
public function load_assets_for_category_page() {
|
||||
global $pagenow;
|
||||
$module = 'category';
|
||||
$is_show = 'edit-tags.php' === $pagenow && isset( $_GET['taxonomy'] ) && 'category' === $_GET['taxonomy']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We not hanlde nonce for load assets.
|
||||
$is_show = apply_filters( 'ppwp_is_load_assets_for_category_page', $is_show );
|
||||
if ( $is_show ) {
|
||||
$this->load_bundle_css( PPW_VERSION );
|
||||
$this->load_css( $module, PPW_VERSION );
|
||||
$this->load_js( $module, PPW_VERSION );
|
||||
wp_localize_script(
|
||||
"ppw-$module-js",
|
||||
'ppw_category_data',
|
||||
array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'home_url' => ppw_core_get_home_url_with_ssl(),
|
||||
'nonce' => wp_create_nonce( 'wp_rest' ),
|
||||
)
|
||||
);
|
||||
$this->load_select2_lib();
|
||||
$this->load_toastr_lib();
|
||||
|
||||
do_action( 'ppw_category_page_load_assets' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render css and js for troubleshoot tab
|
||||
*/
|
||||
public function load_assets_for_troubleshoot_tab() {
|
||||
$module = PPW_Constants::TROUBLESHOOT_SETTINGS_MODULE;
|
||||
if ( PPW_Constants::MENU_NAME === $this->page && ( $module === $this->tab || null === $this->tab ) ) {
|
||||
$this->load_bundle_css( PPW_VERSION );
|
||||
$this->load_js( $module, PPW_VERSION );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load asserts for meta-box.
|
||||
*/
|
||||
public function load_assets_for_meta_box() {
|
||||
$module = PPW_Constants::META_BOX_MODULE;
|
||||
$this->load_css( $module, PPW_VERSION );
|
||||
$this->load_js( $module, PPW_VERSION );
|
||||
wp_localize_script(
|
||||
"ppw-$module-js",
|
||||
'save_password_data',
|
||||
array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'error_message' => array(
|
||||
'duplicate_password' => PPW_Constants::DUPLICATE_PASSWORD,
|
||||
'empty_password' => PPW_Constants::EMPTY_PASSWORD,
|
||||
'space_password' => PPW_Constants::SPACE_PASSWORD,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->load_toastr_lib();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load asserts for shortcodes setting tab.
|
||||
*/
|
||||
public function load_assets_for_shortcodes() {
|
||||
$module = PPW_Constants::SHORTCODES_SETTINGS_MODULE;
|
||||
if ( PPW_Constants::MENU_NAME === $this->page && $module === $this->tab ) {
|
||||
$this->load_bundle_css( PPW_VERSION );
|
||||
$this->load_toastr_lib();
|
||||
$this->load_shared_lib();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render Select2 library
|
||||
*/
|
||||
public function load_select2_lib() {
|
||||
wp_enqueue_script( 'ppw-select2-js', PPW_DIR_URL . 'admin/js/lib/select2.min.js', array( 'jquery' ), '4.0.3', true );
|
||||
wp_enqueue_style( 'ppw-select2-css', PPW_DIR_URL . 'admin/css/lib/select2.min.css', array(), '4.0.3', 'all' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load js file to show notice when deactivating the plugin.
|
||||
*/
|
||||
public function load_js_show_notice_deactivate_plugin() {
|
||||
if ( 'plugins' === $this->screen ) {
|
||||
wp_enqueue_script( 'ppw-notice-deactivate-js', PPW_DIR_URL . 'admin/js/class-ppw-notice-deactivate.js', array( 'jquery' ), PPW_VERSION, true );
|
||||
wp_localize_script(
|
||||
'ppw-notice-deactivate-js',
|
||||
'ppw_deactivate_data',
|
||||
array(
|
||||
'is_active_pro' => is_plugin_active( PPW_Constants::PRO_DIRECTORY ) || is_plugin_active( PPW_Constants::DEV_PRO_DIRECTORY ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the shared lib.
|
||||
*/
|
||||
public function load_shared_lib() {
|
||||
wp_enqueue_script( 'ppw-shared-js', PPW_DIR_URL . 'includes/views/shared/assets/dist/ppwUtils.bundle.js', array( 'jquery' ), PPW_VERSION, true );
|
||||
wp_localize_script(
|
||||
'ppw-shared-js',
|
||||
'ppw_general_data',
|
||||
array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render Toastr library
|
||||
*/
|
||||
public function load_toastr_lib() {
|
||||
wp_enqueue_script( 'ppw-toastr-js', PPW_DIR_URL . 'admin/js/lib/toastr.min.js', array( 'jquery' ), '2.1.3', true );
|
||||
wp_enqueue_style( 'ppw-toastr-css', PPW_DIR_URL . 'admin/css/lib/toastr.min.css', array(), '2.1.3', 'all' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render CSS to hide feature set password of WP
|
||||
*/
|
||||
public function load_css_hide_feature_set_password_wp() {
|
||||
$page_post_screens = apply_filters(
|
||||
PPW_Constants::HOOK_HIDE_DEFAULT_PW_WP_POSITION,
|
||||
array(
|
||||
'edit-post',
|
||||
'edit-page',
|
||||
'page',
|
||||
'post',
|
||||
)
|
||||
);
|
||||
if ( in_array( $this->screen, $page_post_screens, true ) ) {
|
||||
wp_enqueue_style( 'ppw-hide-default-css', PPW_DIR_URL . 'admin/css/ppw-hide-default.css', array(), PPW_VERSION, 'all' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to load css of module
|
||||
*
|
||||
* @param string $module Module for loading.
|
||||
* @param string $version Version to load.
|
||||
* @param array $dependencies Dependencies.
|
||||
*/
|
||||
public function load_css( $module, $version, $dependencies = array() ) {
|
||||
wp_enqueue_style( "ppw-$module-css", PPW_VIEW_URL . "dist/ppw-$module.css", $dependencies, $version, 'all' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load bundle css file
|
||||
*
|
||||
* @param string $version CSS version.
|
||||
*/
|
||||
public function load_bundle_css( $version ) {
|
||||
wp_enqueue_style( 'ppw-bundle-css', PPW_DIR_URL . 'admin/css/dist/ppw-setting.css', array(), $version, 'all' );
|
||||
if ( ppw_is_wp_version_compatible( '5.3' ) ) {
|
||||
wp_enqueue_style( 'ppw-bundle-css-wp-5-3', PPW_DIR_URL . 'includes/views/dist/ppw-general-wp-5-3.css', array(), $version, 'all' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to load js of module
|
||||
*
|
||||
* @param string $module Module for loading.
|
||||
* @param string $version Version to load.
|
||||
* @param array $dependencies Dependencies.
|
||||
*/
|
||||
public function load_js( $module, $version, $dependencies = array() ) {
|
||||
wp_enqueue_script( "ppw-$module-js", PPW_VIEW_URL . "dist/ppw-$module.js", $dependencies, $version, 'all' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
|
||||
use W3TC\Dispatcher;
|
||||
|
||||
if ( ! class_exists( 'PPW_Cache_Services' ) ) {
|
||||
/**
|
||||
* Class PPW_Free_Handle_Cache
|
||||
*/
|
||||
class PPW_Cache_Services {
|
||||
|
||||
public function __construct() {
|
||||
if ( ! function_exists( 'is_plugin_active' ) ) {
|
||||
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle cache for page/post have password type is role with Super Cache plugin
|
||||
*
|
||||
* @param $new_role_password
|
||||
* @param $id
|
||||
* @param $current_roles_password
|
||||
* @param $current_global_passwords
|
||||
* @deprecated
|
||||
*/
|
||||
function handle_cache_for_password_type_role_with_super_cache( $new_role_password, $id, $current_roles_password, $current_global_passwords ) {
|
||||
if ( ! is_plugin_active( 'wp-super-cache/wp-cache.php' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! empty( $new_role_password ) ) {
|
||||
$uri = $this->get_uri_by_post_id( $id );
|
||||
global $cache_rejected_uri;
|
||||
if ( ! in_array( '/' . $uri, $cache_rejected_uri ) ) {
|
||||
$this->add_page_post_to_list_not_cache_for_super_cache( $id, $uri, $cache_rejected_uri );
|
||||
}
|
||||
} else {
|
||||
if ( ! empty( $current_global_passwords ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$result = array_values( $current_roles_password );
|
||||
$result = array_filter( $result, 'strlen' );
|
||||
if ( empty( $result ) ) {
|
||||
$this->remove_page_post_to_list_not_cache_for_super_cache( $id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle cache for page/post have password type is global with Super Cache plugin
|
||||
*
|
||||
* @param $new_global_passwords
|
||||
* @param $id
|
||||
* @param $current_roles_password
|
||||
* @deprecated
|
||||
*/
|
||||
function handle_cache_for_password_type_global_with_super_cache( $new_global_passwords, $id, $current_roles_password ) {
|
||||
if ( ! is_plugin_active( 'wp-super-cache/wp-cache.php' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! empty( $new_global_passwords ) ) {
|
||||
$uri = $this->get_uri_by_post_id( $id );
|
||||
global $cache_rejected_uri;
|
||||
if ( ! in_array( '/' . $uri, $cache_rejected_uri ) ) {
|
||||
$this->add_page_post_to_list_not_cache_for_super_cache( $id, $uri, $cache_rejected_uri );
|
||||
}
|
||||
} else {
|
||||
$result = array_values( $current_roles_password );
|
||||
$result = array_filter( $result, 'strlen' );
|
||||
if ( empty( $result ) ) {
|
||||
$this->remove_page_post_to_list_not_cache_for_super_cache( $id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add page or post to list not cache of WP Super Cache plugin
|
||||
*
|
||||
* @param $post_id
|
||||
* @param $uri
|
||||
* @param $cache_rejected_uri
|
||||
* @deprecated
|
||||
*/
|
||||
function add_page_post_to_list_not_cache_for_super_cache( $post_id, $uri, $cache_rejected_uri ) {
|
||||
// 1. Add URI to list not cache
|
||||
global $wp_cache_config_file;
|
||||
array_push( $cache_rejected_uri, '/' . $uri );
|
||||
$all_uri = array_map( function ( $key, $cache ) {
|
||||
return " $key => '$cache'";
|
||||
}, array_keys( $cache_rejected_uri ), $cache_rejected_uri );
|
||||
$all_uri = implode( ',', $all_uri );
|
||||
$text = "array($all_uri )";
|
||||
wp_cache_replace_line( '^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file );
|
||||
|
||||
// 3. Clear cache by post_id
|
||||
wp_cache_post_edit( $post_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove page or post in list not cache of WP Super Cache plugin
|
||||
*
|
||||
* @param $post_id
|
||||
* @deprecated
|
||||
*/
|
||||
function remove_page_post_to_list_not_cache_for_super_cache( $post_id ) {
|
||||
// 1. Get URI in permalink by post_id
|
||||
$uri = $this->get_uri_by_post_id( $post_id );
|
||||
$uri = '/' . $uri;
|
||||
|
||||
// 2. Remove URI in list not cache
|
||||
global $cache_rejected_uri, $wp_cache_config_file;
|
||||
$cache_rejected_uri = array_unique( $cache_rejected_uri );
|
||||
if ( ( $key = array_search( $uri, $cache_rejected_uri ) ) !== false ) {
|
||||
unset( $cache_rejected_uri[ $key ] );
|
||||
$all_uri = array_map( function ( $key, $cache ) {
|
||||
return " $key => '$cache'";
|
||||
}, array_keys( $cache_rejected_uri ), $cache_rejected_uri );
|
||||
$all_uri = implode( ',', $all_uri );
|
||||
$text = "array($all_uri )";
|
||||
wp_cache_replace_line( '^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get URI by post_id
|
||||
*
|
||||
* @param $post_id
|
||||
*
|
||||
* @return string
|
||||
* @deprecated
|
||||
*/
|
||||
function get_uri_by_post_id( $post_id ) {
|
||||
$permalink = get_permalink( $post_id );
|
||||
$parse_url = parse_url( $permalink );
|
||||
$uri = $parse_url['path'];
|
||||
$uri = explode( '/', $uri );
|
||||
$uri = ! empty( $uri[ count( $uri ) - 1 ] ) ? $uri[ count( $uri ) - 1 ] : $uri[ count( $uri ) - 2 ];
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cache all page
|
||||
* @deprecated
|
||||
*/
|
||||
function clear_cache_super_cache() {
|
||||
if ( ! is_plugin_active( 'wp-super-cache/wp-cache.php' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_multisite() ) {
|
||||
wp_cache_clear_cache( get_current_blog_id() );
|
||||
} else {
|
||||
wp_cache_clear_cache();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check W3 Total Cache has config cookie group
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function check_has_config_w3_total_cache() {
|
||||
$config = Dispatcher::config();
|
||||
$groups = $config->get_array( 'pgcache.cookiegroups.groups' );
|
||||
if ( ! array_key_exists( 'password_protect_wordpress', $groups ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! $groups['password_protect_wordpress']['enabled'] || $groups['password_protect_wordpress']['cache'] ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cookies = $groups['password_protect_wordpress']['cookies'];
|
||||
|
||||
return in_array( 'pda_protect_password', $cookies ) && in_array( 'wp-postpass-role_*', $cookies );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update cookie to option and modify htaccess file for WP Fastest Cache plugin
|
||||
* @deprecated
|
||||
*/
|
||||
function custom_option_exclude_page_and_cookie_fastest_cache() {
|
||||
if ( ! is_plugin_active( 'wp-fastest-cache/wpFastestCache.php' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$old_fastest = get_option( "WpFastestCacheExclude" );
|
||||
$fastest_cache = new WpFastestCache();
|
||||
if ( $old_fastest ) {
|
||||
$old_fastest = json_decode( $old_fastest );
|
||||
$tmp1 = false;
|
||||
$tmp2_free = false;
|
||||
foreach ( $old_fastest as $fast ) {
|
||||
if ( 'cookie' === $fast->type && 'contain' === $fast->prefix && 'pda_protect_password' === $fast->content ) {
|
||||
$tmp1 = true;
|
||||
}
|
||||
if ( 'cookie' === $fast->type && 'contain' === $fast->prefix && 'wp-postpass-role_' === $fast->content ) {
|
||||
$tmp2_free = true;
|
||||
}
|
||||
}
|
||||
if ( ! $tmp1 ) {
|
||||
array_push( $old_fastest, (object) array(
|
||||
'prefix' => 'contain',
|
||||
'content' => 'pda_protect_password',
|
||||
'type' => 'cookie'
|
||||
) );
|
||||
}
|
||||
if ( ! $tmp2_free ) {
|
||||
array_push( $old_fastest, (object) array(
|
||||
'prefix' => 'contain',
|
||||
'content' => 'wp-goldpass-pagepost_',
|
||||
'type' => 'cookie'
|
||||
) );
|
||||
}
|
||||
|
||||
update_option( "WpFastestCacheExclude", json_encode( $old_fastest ) );
|
||||
$fastest_cache->modify_htaccess_for_exclude();
|
||||
} else {
|
||||
$ppwp_cookie = array(
|
||||
(object) array(
|
||||
'prefix' => 'contain',
|
||||
'content' => 'pda_protect_password',
|
||||
'type' => 'cookie'
|
||||
)
|
||||
);
|
||||
|
||||
array_push( $ppwp_cookie, (object) array(
|
||||
'prefix' => 'contain',
|
||||
'content' => 'wp-postpass-role_',
|
||||
'type' => 'cookie'
|
||||
) );
|
||||
|
||||
add_option( "WpFastestCacheExclude", json_encode( $ppwp_cookie ), null, "yes" );
|
||||
$fastest_cache->modify_htaccess_for_exclude();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Class PPW_Category
|
||||
*/
|
||||
class PPW_Category_Service {
|
||||
const COOKIE_NAME = 'ppw_cat-';
|
||||
const OPTION_NAME = 'ppwp_category_options';
|
||||
const SHARED_CATEGORY_TYPE = 'shared_category';
|
||||
|
||||
/**
|
||||
* @var null|integer Category ID.
|
||||
*/
|
||||
private $category_id = null;
|
||||
|
||||
/**
|
||||
* Is using post password required
|
||||
* @var bool
|
||||
*/
|
||||
private $unlocked = false;
|
||||
|
||||
/**
|
||||
* @var null|PPW_Category_Service Instance.
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
private $is_pro_activated;
|
||||
|
||||
/**
|
||||
* Get instance.
|
||||
*
|
||||
* @return PPW_Category_Service
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( is_null( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register hooks.
|
||||
*
|
||||
* @param bool $is_pro_activated Is pro activated
|
||||
*/
|
||||
public function register( $is_pro_activated = false ) {
|
||||
$this->is_pro_activated = $is_pro_activated;
|
||||
$this->unlocked = $this->is_pro_activated;
|
||||
|
||||
add_filter( 'post_password_required', array( $this, 'category_password_required' ), 15, 2 );
|
||||
add_filter( 'ppw_is_valid_password', array( $this, 'check_valid_password' ), 15, 3 );
|
||||
add_action( 'category_pre_add_form', array( $this, 'display_category_ui' ) );
|
||||
|
||||
// Check post is protected before.
|
||||
add_filter( 'ppw_is_valid_cookie', array( $this, 'ppw_is_valid_cookie' ) );
|
||||
add_filter( 'ppwp_post_password_required', array( $this, 'ppwp_post_password_required' ), 100 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if content is protected and unlocked password form.
|
||||
*
|
||||
* @param boolean $is_valid
|
||||
*
|
||||
* @return bool True is valid cookie.
|
||||
*/
|
||||
public function ppw_is_valid_cookie( $is_valid ) {
|
||||
$this->unlocked = $is_valid;
|
||||
|
||||
return $is_valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* If post is protected and
|
||||
*
|
||||
* @param array $data Unlock data from PPWP Fro.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function ppwp_post_password_required( $data ) {
|
||||
if ( ! isset( $data['is_content_unlocked'] ) ) {
|
||||
return $data;
|
||||
}
|
||||
$this->unlocked = $data['is_post_protected'] && $data['is_content_unlocked'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display category UI.
|
||||
*/
|
||||
public function display_category_ui() {
|
||||
$categories = ppw_get_terms_with_all_lang(
|
||||
array(
|
||||
'taxonomy' => 'category',
|
||||
'orderby' => 'name',
|
||||
'order' => 'ASC',
|
||||
'hide_empty' => false,
|
||||
)
|
||||
);
|
||||
$is_protect = ppw_core_get_setting_type_bool_by_option_name( 'ppwp_is_protect_category', self::OPTION_NAME );
|
||||
$protected_categories = ppw_core_get_setting_type_array_by_option_name( 'ppwp_protected_categories_selected', self::OPTION_NAME );
|
||||
|
||||
// Get first password to display to user.
|
||||
$passwords = PPW_Repository_Passwords::get_instance()->get_all_shared_categories_password();
|
||||
if ( count( $passwords ) > 0 ) {
|
||||
$password = $passwords[0]->password;
|
||||
} else {
|
||||
$password = '';
|
||||
}
|
||||
|
||||
ob_start();
|
||||
include PPW_DIR_PATH . 'includes/views/category/view-option.php';
|
||||
echo ob_get_clean(); // phpcs:ignore -- we already escape on the view-option.php
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters whether a category requires the user to supply a password.
|
||||
*
|
||||
* @param bool Whether the user needs to supply a password.
|
||||
* True if password has not been provided or is incorrect,
|
||||
* false if password has been supplied or is not required.
|
||||
*
|
||||
* @return bool false if a password is not required or the correct password cookie is present, true otherwise.
|
||||
*/
|
||||
public function category_password_required( $required, $post ) {
|
||||
$post_id = ! empty( $post ) ? $post->ID : false;
|
||||
if ( ! $post_id ) {
|
||||
return $required;
|
||||
}
|
||||
|
||||
// Get all protected categories of a Post.
|
||||
$protected_categories = $this->get_protected_categories( $post_id );
|
||||
if ( empty( $protected_categories ) ) {
|
||||
return $required;
|
||||
}
|
||||
|
||||
$validated_cookie = apply_filters( 'ppw_category_is_valid_cookie', $this->is_valid_cookie(), $post_id, $post, $required );
|
||||
if ( $validated_cookie ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
add_filter( 'ppwp_ppf_action_url', array( $this, 'get_action_url' ), 9999 );
|
||||
|
||||
// Unlocked by PPWP Free and PPWP Pro
|
||||
// Include Single, AL, Group.
|
||||
if ( apply_filters( 'ppw_category_unlocked', $this->unlocked, $post_id, $protected_categories ) ) {
|
||||
$this->unlocked = $this->is_pro_activated;
|
||||
|
||||
return $required;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get protected categories if user turn on Option.
|
||||
*
|
||||
* @param integer $post_id Post ID.
|
||||
*
|
||||
* @return array Empty if user turn off option or post ID not include protected categories.
|
||||
*/
|
||||
public function get_protected_categories( $post_id ) {
|
||||
// Check user has turn on option.
|
||||
$enabled = ppw_core_get_setting_type_bool_by_option_name( 'ppwp_is_protect_category', self::OPTION_NAME );
|
||||
$enabled = apply_filters( 'ppw_category_is_enabled', $enabled, $post_id );
|
||||
if ( ! $enabled ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$categories_id = $this->get_categories_by_post_id( $post_id );
|
||||
|
||||
// Not handle with categories of post are empty.
|
||||
if ( empty( $categories_id ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// Get protected categories of current post.
|
||||
$protected_categories = ppw_core_get_setting_type_array_by_option_name( 'ppwp_protected_categories_selected', self::OPTION_NAME );;
|
||||
$protected_categories = array_intersect( $categories_id, $protected_categories );
|
||||
|
||||
// Reorder index of array.
|
||||
return array_values( $protected_categories );
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace current action by action URL of category to check password.
|
||||
*/
|
||||
public function get_action_url( $url ) {
|
||||
if ( is_category() ) {
|
||||
$callback_url = get_category_link( get_queried_object_id() );
|
||||
} elseif ( is_singular() ) {
|
||||
$callback_url = get_the_permalink();
|
||||
} else {
|
||||
global $wp;
|
||||
$callback_url = home_url( $wp->request );
|
||||
}
|
||||
|
||||
$callback_url = rawurlencode( $callback_url );
|
||||
|
||||
return add_query_arg(
|
||||
array(
|
||||
PPW_Constants::CALL_BACK_URL_PARAM => $callback_url,
|
||||
),
|
||||
$url
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check password is valid after show message if it is wrong password.
|
||||
*
|
||||
* @param bool $is_valid Is valid password.
|
||||
* @param int $post_id Post ID.
|
||||
* @param string $password Password.
|
||||
*
|
||||
* @return bool True if password is valid.
|
||||
*/
|
||||
public function check_valid_password( $is_valid, $post_id, $password ) {
|
||||
$protected_categories = $this->get_protected_categories( $post_id );
|
||||
if ( empty( $protected_categories ) ) {
|
||||
return $is_valid;
|
||||
}
|
||||
|
||||
return apply_filters( 'ppw_category_is_valid_password', $this->is_valid_password( $protected_categories, $password, $post_id ), $is_valid, $protected_categories, $post_id, $password ) || $is_valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set password to cookie
|
||||
*
|
||||
* @param string $password Password string.
|
||||
* @param string $cookie_name Cookie name.
|
||||
* @param false|int $password_id Password ID.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function set_password_to_cookie( $password, $cookie_name, $password_id = false ) {
|
||||
$password_hashed = wp_hash_password( $password );
|
||||
$expire = apply_filters( PPW_Constants::HOOK_COOKIE_EXPIRED, time() + 7 * DAY_IN_SECONDS );
|
||||
$password_cookie_expired = ppw_core_get_setting_type_string( PPW_Constants::COOKIE_EXPIRED );
|
||||
if ( ! empty( $password_cookie_expired ) ) {
|
||||
$time = explode( ' ', $password_cookie_expired )[0];
|
||||
$unit = ppw_core_get_unit_time( $password_cookie_expired );
|
||||
if ( 0 !== $unit ) {
|
||||
$expire = apply_filters( PPW_Constants::HOOK_COOKIE_EXPIRED, time() + (int) $time * $unit );
|
||||
}
|
||||
}
|
||||
|
||||
$referer = wp_get_referer();
|
||||
if ( $referer ) {
|
||||
$secure = ( 'https' === parse_url( $referer, PHP_URL_SCHEME ) );
|
||||
} else {
|
||||
$secure = false;
|
||||
}
|
||||
|
||||
if ( $password_id ) {
|
||||
$password_hashed = $password_id . '|' . $password_hashed;
|
||||
}
|
||||
|
||||
$expire = apply_filters( 'ppw_cookie_expire', $expire );
|
||||
$expire = apply_filters( 'ppwp_cookie_expiry', $expire );
|
||||
return setcookie( $cookie_name . COOKIEHASH, $password_hashed, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle password with data sent by user.
|
||||
*
|
||||
* @param array $categories_id Categories ID.
|
||||
* @param string $password Password.
|
||||
* @param integer $post_id Post ID.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_valid_password( $categories_id, $password, $post_id ) {
|
||||
// Get current roles will empty if user using subdomain because path of cookie.
|
||||
$password_info = PPW_Repository_Passwords::get_instance()->find_by_shared_category_password( $password );
|
||||
if ( ! $password_info ) {
|
||||
return false;
|
||||
}
|
||||
$this->set_password_to_cookie( $password, self::COOKIE_NAME, $password_info->id );
|
||||
$this->set_password_to_cookie( $password, PPW_Constants::WP_POST_PASS );
|
||||
|
||||
do_action( 'ppw_category_after_set_password_to_cookie', $categories_id, $password_info, $post_id );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is valid cookie.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_valid_cookie() {
|
||||
$_cookie = wp_unslash( $_COOKIE );
|
||||
if ( ! isset( $_cookie[ self::COOKIE_NAME . COOKIEHASH ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cookie_value = $_cookie[ self::COOKIE_NAME . COOKIEHASH ];
|
||||
$cookie_value = explode( '|', $cookie_value );
|
||||
if ( count( $cookie_value ) < 2 ) {
|
||||
return false;
|
||||
}
|
||||
$password_id = (int) $cookie_value[0];
|
||||
$password_hashed = $cookie_value[1];
|
||||
|
||||
$password_info = PPW_Repository_Passwords::get_instance()->get_shared_category_password( $password_id );
|
||||
if ( ! $password_info ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ppw_free_check_password( $password_info->password, $password_hashed ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get categories by post ID.
|
||||
*
|
||||
* @param int $post_id Post ID.
|
||||
*
|
||||
* @return array|WP_Error The requested term data or empty array if no terms found. WP_Error if any of the
|
||||
* taxonomies don't exist.
|
||||
* @link https://developer.wordpress.org/reference/functions/wp_get_post_categories/
|
||||
*/
|
||||
public function get_categories_by_post_id( $post_id ) {
|
||||
$terms = get_the_terms( $post_id, $this->get_current_taxonomy( $post_id ) );
|
||||
|
||||
if ( empty( $terms ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return array_map(
|
||||
function ( $term ) {
|
||||
return $term->term_id;
|
||||
},
|
||||
$terms
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current taxonomy from Post ID.
|
||||
*
|
||||
* @param int $post_id Post ID.
|
||||
*
|
||||
* @return string Current taxonomy.
|
||||
*/
|
||||
public function get_current_taxonomy( $post_id ) {
|
||||
return apply_filters( 'ppw_category_get_taxonomy', 'category', $post_id );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,510 @@
|
||||
<?php
|
||||
|
||||
class PPW_Content_Protection {
|
||||
/**
|
||||
* @var PPW_Content_Protection
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
const POST_TYPE = 'ppwp-section';
|
||||
|
||||
const SETTING_META_KEY = 'ppw_pcp_setting';
|
||||
|
||||
const PASSWORD_GLOBAL_TYPE = 'PCPSection';
|
||||
|
||||
const PASSWORD_ROLE_TYPE = 'PCPSectionRole_';
|
||||
|
||||
const COOKIE_NAME = 'ppw_section-';
|
||||
|
||||
const ADMIN_PATH = 'edit.php?post_type=ppwp-section';
|
||||
|
||||
const SHORTCODE_COLUMN = 'ppw_pcp_shortcode';
|
||||
|
||||
/**
|
||||
* @var PPW_Password_Services
|
||||
*/
|
||||
private $password_service;
|
||||
|
||||
/**
|
||||
* @var PPW_Repository_Passwords
|
||||
*/
|
||||
private $password_repo;
|
||||
|
||||
/**
|
||||
* @return PPW_Content_Protection
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
$this->password_service = new PPW_Password_Services();
|
||||
$this->password_repo = new PPW_Repository_Passwords();
|
||||
}
|
||||
|
||||
public function register() {
|
||||
add_action( 'init', array( $this, 'register_post_type' ) );
|
||||
add_action( 'wp_ajax_ppw_pcp_validate_password', array( $this, 'validate_password' ) );
|
||||
add_action( 'wp_ajax_nopriv_ppw_pcp_validate_password', array( $this, 'validate_password' ) );
|
||||
add_filter( 'ppw_shortcode_render_content', array( $this, 'handle_shortcode_with_area' ), 10, 2 );
|
||||
add_filter( 'et_builder_load_actions', array( $this, 'add_action_to_divi' ) );
|
||||
add_filter( 'ppw_pcp_valid_shortcode', array( $this, 'valid_shortcode' ), 10, 2 );
|
||||
add_action( 'admin_init', array( $this, 'maybe_add_metabox' ) );
|
||||
add_filter( 'ppw_shortcode_unlock_content', array( $this, 'maybe_unlock_content_by_cookie' ), 15, 2 );
|
||||
add_filter( 'ppw_pcp_submenu_add_new_tab', array( $this, 'add_pcp_tab' ), 1000 );
|
||||
add_filter( 'manage_' . self::POST_TYPE . '_posts_columns', array( $this, 'add_shortcode_column' ) );
|
||||
add_action( 'manage_' . self::POST_TYPE . '_posts_custom_column', array(
|
||||
$this,
|
||||
'render_content_custom_column',
|
||||
), 10, 2 );
|
||||
add_action( 'admin_notices', array( $this, 'handle_admin_notices' ) );
|
||||
}
|
||||
|
||||
public function add_shortcode_column( $columns ) {
|
||||
$inserted = array(
|
||||
self::SHORTCODE_COLUMN => 'Shortcode'
|
||||
);
|
||||
|
||||
return array_slice( $columns, 0, 2, true )
|
||||
+ $inserted
|
||||
+ array_slice( $columns, 2, count( $columns ) - 1, true );
|
||||
}
|
||||
|
||||
public function render_content_custom_column( $column, $post_id ) {
|
||||
if ( $column === self::SHORTCODE_COLUMN ) {
|
||||
echo '[ppwp section="' . absint( $post_id ) . '" /]';
|
||||
}
|
||||
}
|
||||
|
||||
public function add_pcp_tab( $tabs ) {
|
||||
$tabs[] = array(
|
||||
'tab' => 'section',
|
||||
'tab_name' => 'Section Protection',
|
||||
'link' => self::ADMIN_PATH,
|
||||
);
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
public function valid_shortcode( $content, $attrs ) {
|
||||
if ( ! isset( $attrs['section'] ) || ! is_numeric( $attrs['section'] ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
if ( absint( $attrs['section'] ) > 0 ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function register_post_type() {
|
||||
$args = array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Section Protection', 'password-protect-page' ),
|
||||
'singular_name' => __( 'Section Protection', 'password-protect-page' ),
|
||||
'add_new' => __( 'Add New', 'password-protect-page' ),
|
||||
'add_new_item' => __( 'Add New', 'password-protect-page' ),
|
||||
'edit_item' => __( 'Edit', 'password-protect-page' ),
|
||||
'new_item' => __( 'New', 'password-protect-page' ),
|
||||
'view_item' => __( 'View', 'password-protect-page' ),
|
||||
'search_items' => __( 'Search', 'password-protect-page' ),
|
||||
'not_found' => __( 'No found', 'password-protect-page' ),
|
||||
'not_found_in_trash' => __( 'No found in Trash', 'password-protect-page' ),
|
||||
),
|
||||
'public' => false,
|
||||
'hierarchical' => true,
|
||||
'show_ui' => true,
|
||||
'show_in_menu' => self::ADMIN_PATH,
|
||||
'_builtin' => false,
|
||||
'capability_type' => 'post',
|
||||
'supports' => array( 'title', 'editor' ),
|
||||
'rewrite' => false,
|
||||
'query_var' => false,
|
||||
'show_in_rest' => true,
|
||||
);
|
||||
|
||||
if ( current_user_can( 'administrator' ) ) {
|
||||
$args['public'] = true;
|
||||
$args['publicly_queryable'] = true;
|
||||
}
|
||||
|
||||
// if ( is_admin() ) {
|
||||
// global $pagenow, $typenow, $post;
|
||||
// if ( 'edit.php' === $pagenow || self::POST_TYPE === $typenow ) {
|
||||
// $args['show_in_menu'] = PPW_Constants::MENU_NAME;
|
||||
// } elseif ( isset( $_GET['post_type'] ) && self::POST_TYPE === $_GET['post_type'] ) {
|
||||
// $args['show_in_menu'] = PPW_Constants::MENU_NAME;
|
||||
// } elseif ( isset( $_GET['post'] ) && isset( $_GET['action'] ) ) {
|
||||
// $post_type = get_post_type( $_GET['post'] );
|
||||
//
|
||||
// if ( $post_type === self::POST_TYPE ) {
|
||||
// $args['show_in_menu'] = PPW_Constants::MENU_NAME;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
register_post_type( self::POST_TYPE, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add ajax support for Divi builder.
|
||||
*
|
||||
* @param array $actions array of allowed actions.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_action_to_divi( $actions ) {
|
||||
$actions[] = 'ppw_pcp_validate_password';
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
public function handle_shortcode_with_area( $content, $attrs ) {
|
||||
if ( ! isset( $attrs['section'] ) ) {
|
||||
return $content;
|
||||
}
|
||||
$post_id = absint( $attrs['section'] );
|
||||
if ( ! $post_id ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$post = get_post( $post_id );
|
||||
if ( empty( $post ) || $post->post_type !== self::POST_TYPE ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$post_content = $this->massage_post_content( $post_id, $post->post_content );
|
||||
if ( is_null( $post_content ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
return $post_content;
|
||||
}
|
||||
|
||||
public function massage_post_content( $post_id, $post_content ) {
|
||||
$post_content = ppw_support_third_party_content_plugin( $post_id, $post_content );
|
||||
|
||||
return apply_filters( 'the_content', $post_content );
|
||||
}
|
||||
|
||||
public function maybe_add_metabox() {
|
||||
$attributes = apply_filters(
|
||||
'ppw_pcp_metabox_attributes',
|
||||
array(
|
||||
'title' => __( 'Password Protect WordPress', PPW_Constants::DOMAIN ),
|
||||
'callback' => array( $this, 'display_metabox' ),
|
||||
'screen' => array( self::POST_TYPE ),
|
||||
'context' => 'side',
|
||||
'priority' => 'high',
|
||||
)
|
||||
);
|
||||
|
||||
add_meta_box(
|
||||
'ppw_pcp_meta_box',
|
||||
$attributes['title'],
|
||||
$attributes['callback'],
|
||||
$attributes['screen'],
|
||||
$attributes['context'],
|
||||
$attributes['priority']
|
||||
);
|
||||
}
|
||||
|
||||
public function display_metabox() {
|
||||
ob_start();
|
||||
?>
|
||||
<div id="ppw-pcp-metabox"></div>
|
||||
<?php
|
||||
wp_enqueue_script( 'ppw-pcp-metabox', PPW_DIR_URL . 'admin/js/dist/pcp-metabox.js', array(), PPW_VERSION, true );
|
||||
wp_localize_script(
|
||||
'ppw-pcp-metabox',
|
||||
'pcpMetabox',
|
||||
array(
|
||||
'rest_url' => get_rest_url( null, '/wppp/v1/pcp' ),
|
||||
'nonce' => wp_create_nonce( 'wp_rest' ),
|
||||
'post_id' => get_the_ID(),
|
||||
'customize_url' => admin_url( 'customize.php' ),
|
||||
'extra_html' => apply_filters( 'ppw_pcp_metabox_extra_html', '')
|
||||
)
|
||||
);
|
||||
|
||||
echo ob_get_clean(); // phpcs:ignore -- we cannot escape ob_start ob_get_clean(), there are no variable to escape in statement above
|
||||
}
|
||||
|
||||
public function validate_single_password( $params ) {
|
||||
$password = $params['password'];
|
||||
$area = $params['area'];
|
||||
$roles = ppw_core_get_current_role();
|
||||
$args = array(
|
||||
'post_id' => $area,
|
||||
'roles' => $roles,
|
||||
'global_type' => self::PASSWORD_GLOBAL_TYPE,
|
||||
'role_type' => self::PASSWORD_ROLE_TYPE,
|
||||
);
|
||||
|
||||
$password_info = $this->password_repo->find_activated_password( $password, $args );
|
||||
if ( empty( $password_info ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->password_service->set_cookie_bypass_cache( $password, self::COOKIE_NAME . $area . 'p' . $password_info->id );
|
||||
|
||||
do_action( 'ppw_after_save_section_cookie', $password_info );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate_password() {
|
||||
if ( ! isset( $_POST['pss'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Processing form data without nonce verification. - Not verify nonce for password validate.
|
||||
wp_send_json(
|
||||
array(
|
||||
'success' => false,
|
||||
'message' => 'Please enter the correct password!',
|
||||
),
|
||||
403
|
||||
);
|
||||
exit();
|
||||
}
|
||||
|
||||
if ( ! isset( $_POST['area'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Processing form data without nonce verification. - Not verify nonce for password validate.
|
||||
wp_send_json(
|
||||
array(
|
||||
'success' => false,
|
||||
'message' => 'Area value is required!',
|
||||
),
|
||||
403
|
||||
);
|
||||
exit();
|
||||
}
|
||||
|
||||
if ( ! isset( $_POST['post_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Processing form data without nonce verification. - Not verify nonce for password validate.
|
||||
wp_send_json(
|
||||
array(
|
||||
'success' => false,
|
||||
'message' => 'Post ID is required!',
|
||||
),
|
||||
403
|
||||
);
|
||||
exit();
|
||||
}
|
||||
$password = wp_unslash( $_POST['pss'] ); // phpcs:ignore -- not sanitize password because we allow all character.
|
||||
$area = absint( $_POST['area'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Processing form data without nonce verification. - Not verify nonce for password validate.
|
||||
$post_id = absint( $_POST['post_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Processing form data without nonce verification. - Not verify nonce for password validate.
|
||||
|
||||
$post = get_post( $area );
|
||||
if ( empty( $post ) ) {
|
||||
wp_send_json(
|
||||
array(
|
||||
'success' => false,
|
||||
'message' => 'Post does not exist',
|
||||
),
|
||||
403
|
||||
);
|
||||
exit();
|
||||
}
|
||||
if ( $post->post_type !== self::POST_TYPE ) {
|
||||
wp_send_json(
|
||||
array(
|
||||
'success' => false,
|
||||
'message' => 'Post type is not valid',
|
||||
),
|
||||
403
|
||||
);
|
||||
exit();
|
||||
}
|
||||
|
||||
$setting = get_post_meta( $area, self::SETTING_META_KEY, true );
|
||||
$params = array(
|
||||
'password' => $password,
|
||||
'area' => $area,
|
||||
'post_id' => $post_id,
|
||||
'setting' => $setting,
|
||||
);
|
||||
|
||||
$is_valid_by_single = $this->validate_single_password( $params );
|
||||
$is_valid_password = apply_filters( 'ppw_pcp_area_is_valid_password', $is_valid_by_single, $params );
|
||||
if ( $is_valid_password ) {
|
||||
wp_send_json(
|
||||
array(
|
||||
'reload' => ! ppw_core_get_setting_type_bool_by_option_name( PPW_Constants::NO_RELOAD_PAGE, PPW_Constants::MISC_OPTIONS ),
|
||||
'success' => true,
|
||||
'message' => '',
|
||||
'content' => $this->massage_post_content( $area, $post->post_content ),
|
||||
),
|
||||
200
|
||||
);
|
||||
exit();
|
||||
}
|
||||
|
||||
wp_send_json(
|
||||
array(
|
||||
'success' => false,
|
||||
'message' => get_theme_mod( 'ppwp_pcp_err_msg_text', PPW_Constants::DEFAULT_SHORTCODE_ERROR_MSG ),
|
||||
),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
public function check_area_exist( $post ) {
|
||||
if ( empty( $post ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $post->post_type !== self::POST_TYPE ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get_info_from_area_cookie( $area ) {
|
||||
$_cookie = wp_unslash( $_COOKIE );
|
||||
if ( empty( $_cookie ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$cookie_keys = array_filter(
|
||||
array_keys( $_cookie ),
|
||||
function ( $key ) {
|
||||
return false !== strpos( $key, self::COOKIE_NAME );
|
||||
}
|
||||
);
|
||||
|
||||
if ( 0 === count( $cookie_keys ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$results = array();
|
||||
foreach ( $cookie_keys as $cookie_key ) {
|
||||
$info = str_replace( self::COOKIE_NAME, '', $cookie_key );
|
||||
$info = str_replace( COOKIEHASH, '', $info );
|
||||
$info = explode( 'p', $info );
|
||||
|
||||
$password_id = absint( ppw_get_value( $info, 1, 0 ) );
|
||||
$cookie_area = absint( ppw_get_value( $info, 0, 0 ) );
|
||||
|
||||
if ( $area !== $cookie_area ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$results[ $password_id ] = array(
|
||||
'cookie_name' => $cookie_key,
|
||||
'cookie_value' => $_cookie[ $cookie_key ],
|
||||
);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function validate_cookie( $area ) {
|
||||
$cookie_passwords = $this->get_info_from_area_cookie( $area );
|
||||
if ( empty( $cookie_passwords ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$password_ids = array_keys( $cookie_passwords );
|
||||
$roles = ppw_core_get_current_role();
|
||||
$params = array(
|
||||
'post_id' => $area,
|
||||
'roles' => $roles,
|
||||
'global_type' => self::PASSWORD_GLOBAL_TYPE,
|
||||
'role_type' => self::PASSWORD_ROLE_TYPE,
|
||||
'allow_to_check_expired' => false,
|
||||
);
|
||||
|
||||
$password_infos = $this->password_repo->find_activated_passwords_by_ids(
|
||||
$password_ids,
|
||||
$params
|
||||
);
|
||||
|
||||
if ( empty( $password_infos ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ( $password_infos as $password_info ) {
|
||||
if ( ! isset( $cookie_passwords[ $password_info->id ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$cookie = $cookie_passwords[ $password_info->id ];
|
||||
$hashed_password = $cookie['cookie_value'];
|
||||
|
||||
if ( ppw_free_check_password( $password_info->password, $hashed_password ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function maybe_unlock_content_by_cookie( $is_valid, $attrs ) {
|
||||
if ( $is_valid || ! isset( $attrs['section'] ) ) {
|
||||
return $is_valid;
|
||||
}
|
||||
|
||||
$area = $attrs['section'];
|
||||
$setting = get_post_meta( $area, self::SETTING_META_KEY, true );
|
||||
|
||||
$post = get_post( $area );
|
||||
if ( ! $this->check_area_exist( $post ) ) {
|
||||
return $is_valid;
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'area' => absint( $area ),
|
||||
'setting' => $setting,
|
||||
);
|
||||
|
||||
$is_valid_cookie = $this->validate_cookie( $params['area'] );
|
||||
|
||||
return apply_filters( 'ppw_pcp_valid_area_password', $is_valid_cookie, $params );
|
||||
}
|
||||
|
||||
public function handle_admin_notices() {
|
||||
if ( ! function_exists( 'get_current_screen' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current_screen = get_current_screen();
|
||||
if ( ! isset( $current_screen->post_type ) ) {
|
||||
return;
|
||||
}
|
||||
if ( $current_screen->post_type !== self::POST_TYPE ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$button_contexts = array( 'ppwp-section' );
|
||||
if ( in_array( $current_screen->id, $button_contexts ) ) {
|
||||
$edit_url = admin_url( self::ADMIN_PATH );
|
||||
$button = '<span style="float: right;">
|
||||
<a href="' . $edit_url . '">
|
||||
<button class="button button-primary">
|
||||
Go back to all sections
|
||||
</button>
|
||||
</a>
|
||||
</span>';
|
||||
} else {
|
||||
$button = '';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<div class="notice">
|
||||
<p>
|
||||
<div>
|
||||
<b>Password Protect WordPress: Section Protection</b>
|
||||
<?php echo $button;?>
|
||||
</div>
|
||||
<a target="_blank" rel="noopener noreferrer"
|
||||
href="https://passwordprotectwp.com/docs/section-protection/?utm_source=user-website&utm_medium=section-protection-list&utm_campaign=ppwp-free">Protect section of your
|
||||
content</a> by creating section templates below. Add these sections to your content using
|
||||
auto-generated section shortcodes.
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,816 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'PPW_Customizer_PCP' ) ) {
|
||||
class PPW_Customizer_PCP {
|
||||
|
||||
/**
|
||||
* Instance of PPW_Pro_Shortcode class.
|
||||
*
|
||||
* @var PPW_Customizer_PCP
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
const PANEL = 'ppwp_pcp';
|
||||
const GENERAL_SECTION = 'ppwp_pcp_form';
|
||||
const FORM_SECTION = 'ppwp_pcp_form';
|
||||
const ERR_MSG_SECTION = 'ppwp_pcp_err_msg';
|
||||
const BUTTON_SECTION = 'ppwp_pcp_button';
|
||||
|
||||
/**
|
||||
* Get instance of PPW_Customizer
|
||||
*
|
||||
* @return PPW_Customizer_PCP
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( is_null( self::$instance ) ) {
|
||||
// Use static instead of self due to the inheritance later.
|
||||
// For example: ChildSC extends this class, when we call get_instance
|
||||
// it will return the object of child class. On the other hand, self function
|
||||
// will return the object of base class.
|
||||
self::$instance = new static();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function register() {
|
||||
add_action( 'customize_register', array( $this, 'customize_register' ), 15 );
|
||||
add_action( 'wp_head', array( $this, 'dynamic_styles' ) );
|
||||
add_filter( 'ppw_pcp_attributes', array( $this, 'load_customizer_attributes' ) );
|
||||
add_filter( 'ppw_validated_pcp_password', array( $this, 'load_customizer_err_msg' ), 10, 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load customizer attributes.
|
||||
*
|
||||
* @param array $attrs Attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function load_customizer_attributes( $attrs ) {
|
||||
$attrs['headline'] = get_theme_mod( 'ppwp_pcp_form_headline', PPW_Constants::DEFAULT_SHORTCODE_HEADLINE );
|
||||
$attrs['description'] = get_theme_mod( 'ppwp_pcp_form_description', PPW_Constants::DEFAULT_SHORTCODE_DESCRIPTION );
|
||||
$attrs['label'] = get_theme_mod( 'ppwp_pcp_form_label', PPW_Constants::DEFAULT_SHORTCODE_LABEL );
|
||||
$attrs['placeholder'] = get_theme_mod( 'ppwp_pcp_form_placeholder', '' );
|
||||
$attrs['error_msg'] = get_theme_mod( 'ppwp_pcp_err_msg_text', PPW_Constants::DEFAULT_SHORTCODE_ERROR_MSG );
|
||||
$attrs['button'] = get_theme_mod( 'ppwp_pcp_button_text', PPW_Constants::DEFAULT_SHORTCODE_BUTTON );
|
||||
$attrs['loading'] = get_theme_mod( 'ppwp_pcp_button_loading_text', PPW_Constants::DEFAULT_SHORTCODE_LOADING );
|
||||
$attrs['show_password'] = get_theme_mod( 'ppwp_pcp_form_is_show_password', PPW_Constants::DEFAULT_SHORTCODE_SHOW_PASSWORD );
|
||||
$attrs['show_password_text'] = get_theme_mod( 'ppwp_pcp_form_show_password_text', PPW_Constants::DEFAULT_SHORTCODE_SHOW_PASSWORD_TEXT );
|
||||
// $attrs['desc_above_btn'] = get_theme_mod( 'ppwp_pcp_description_above_btn', PPW_Constants::DEFAULT_SHORTCODE_DESC_ABOVE_PWD_BTN );
|
||||
$attrs['desc_below_form'] = get_theme_mod( 'ppwp_pcp_description_below_form', PPW_Constants::DEFAULT_SHORTCODE_DESC_BELOW_PWD_FORM );
|
||||
|
||||
return $attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load customizer error message.
|
||||
*
|
||||
* @param array $attrs Attributes.
|
||||
* @param string $password Password.
|
||||
* @param array $parsed_attrs Parsed attributes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function load_customizer_err_msg( $attrs, $password, $parsed_attrs ) {
|
||||
if ( isset( $parsed_attrs['error_msg'] ) ) {
|
||||
return $attrs;
|
||||
}
|
||||
if ( isset( $attrs['is_valid_password'] ) && ! $attrs['is_valid_password'] ) {
|
||||
$attrs['message'] = get_theme_mod( 'ppwp_pcp_err_msg_text', PPW_Constants::DEFAULT_SHORTCODE_ERROR_MSG );
|
||||
}
|
||||
|
||||
return $attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register customizer.
|
||||
*
|
||||
* @param WP_Customize $wp_customize WP Customize class.
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
if ( ! class_exists( 'PPW_Title_Group_Control' ) ) {
|
||||
include PPW_DIR_PATH . 'includes/customizers/class-ppw-title-group-control.php';
|
||||
}
|
||||
if ( ! class_exists( 'PPW_Toggle_Control' ) ) {
|
||||
include PPW_DIR_PATH . 'includes/customizers/class-ppw-toggle-control.php';
|
||||
}
|
||||
if ( ! class_exists( 'PPW_Text_Editor_Custom_Control' ) ) {
|
||||
include PPW_DIR_PATH . 'includes/customizers/class-ppw-text-editor-control.php';
|
||||
}
|
||||
|
||||
$wp_customize->add_panel(
|
||||
self::PANEL,
|
||||
array(
|
||||
'priority' => 9990,
|
||||
'capability' => 'edit_theme_options',
|
||||
'theme_supports' => '',
|
||||
'title' => __( 'PPWP Partial Protection Form', 'password-protect-page' ),
|
||||
)
|
||||
);
|
||||
|
||||
$this->append_form_section( $wp_customize );
|
||||
$this->append_err_msg_section( $wp_customize );
|
||||
$this->append_button_section( $wp_customize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Append form section.
|
||||
*
|
||||
* @param WP_Customize $wp_customize WP Customize class.
|
||||
*/
|
||||
public function append_form_section( $wp_customize ) {
|
||||
$wp_customize->add_section(
|
||||
self::FORM_SECTION,
|
||||
array(
|
||||
'title' => __( 'Password Form', 'password-protect-page' ),
|
||||
'panel' => self::PANEL,
|
||||
'priority' => 10,
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_background_title' );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Title_Group_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_form_background_title', array(
|
||||
'label' => __( 'Background', 'password-protect-page' ),
|
||||
'section' => self::FORM_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_background_title',
|
||||
'type' => 'control_title',
|
||||
'priority' => 0,
|
||||
) )
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_background_color' );
|
||||
$wp_customize->add_control(
|
||||
new WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_form_background_color_control',
|
||||
array(
|
||||
'label' => __( 'Form Background Color', 'password-protect-page' ),
|
||||
'section' => self::FORM_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_background_color',
|
||||
'priority' => 10,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_padding' );
|
||||
$wp_customize->add_control(
|
||||
'ppwp_pcp_form_padding_control',
|
||||
array(
|
||||
'label' => __( 'Padding', 'password-protect-page' ),
|
||||
'description' => __( 'Padding in px', 'password-protect-page' ),
|
||||
'section' => self::FORM_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_padding',
|
||||
'type' => 'number',
|
||||
'priority' => 20,
|
||||
)
|
||||
);
|
||||
|
||||
/* form background border radius */
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_border_radius', array(
|
||||
'default' => PPW_Constants::DEFAULT_FORM_BORDER_RADIUS,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_form_border_radius_control', array(
|
||||
'label' => __( 'Border Radius', 'password-protect-page' ),
|
||||
'section' => self::GENERAL_SECTION,
|
||||
'description' => 'Border Radius in px',
|
||||
'settings' => 'ppwp_pcp_form_border_radius',
|
||||
'type' => 'number',
|
||||
'priority' => 40,
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_headline_title' );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Title_Group_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_form_headline_title', array(
|
||||
'label' => __( 'Headline', 'password-protect-page' ),
|
||||
'section' => self::GENERAL_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_headline_title',
|
||||
'type' => 'control_title',
|
||||
'priority' => 50,
|
||||
) )
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_headline', array(
|
||||
'default' => PPW_Constants::DEFAULT_SHORTCODE_HEADLINE,
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Text_Editor_Custom_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_form_headline',
|
||||
array(
|
||||
'label' => __( 'Headline', 'password-protect-page' ),
|
||||
'section' => self::GENERAL_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_headline',
|
||||
'type' => 'textarea',
|
||||
'priority' => 60,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_headline_font_size', array(
|
||||
'default' => PPW_Constants::DEFAULT_HEADLINE_FONT_SIZE,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_form_headline_font_size_control', array(
|
||||
'label' => __( 'Font Size', 'password-protect-page' ),
|
||||
'description' => __( 'Font size in px', 'password-protect-page' ),
|
||||
'section' => self::GENERAL_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_headline_font_size',
|
||||
'type' => 'number',
|
||||
'priority' => 70,
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_headline_font_weight', array(
|
||||
'default' => PPW_Constants::DEFAULT_HEADLINE_FONT_WEIGHT,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_form_headline_font_weight_control', array(
|
||||
'label' => __( 'Font Weight', 'password-protect-page' ),
|
||||
'section' => self::GENERAL_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_headline_font_weight',
|
||||
'type' => 'number',
|
||||
'priority' => 80,
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_headline_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_HEADLINE_FONT_COLOR,
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_form_headline_color_control', array(
|
||||
'label' => __( 'Text Color', 'password-protect-page' ),
|
||||
'section' => self::GENERAL_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_headline_color',
|
||||
'priority' => 90,
|
||||
) )
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_description_title' );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Title_Group_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_form_description_title', array(
|
||||
'label' => __( 'Description Above Form', 'password-protect-page' ),
|
||||
'section' => self::GENERAL_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_description_title',
|
||||
'type' => 'control_title',
|
||||
'priority' => 100,
|
||||
) )
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_description', array(
|
||||
'default' => PPW_Constants::DEFAULT_SHORTCODE_DESCRIPTION,
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Text_Editor_Custom_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_form_description',
|
||||
array(
|
||||
'label' => __( 'Description', 'password-protect-page' ),
|
||||
'section' => self::GENERAL_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_description',
|
||||
'type' => 'textarea',
|
||||
'priority' => 110,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_description_font_size', array(
|
||||
'default' => PPW_Constants::DEFAULT_TEXT_FONT_SIZE,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_form_description_font_size_control', array(
|
||||
'label' => __( 'Font Size', 'password-protect-page' ),
|
||||
'description' => __( 'Font size in px', 'password-protect-page' ),
|
||||
'section' => self::GENERAL_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_description_font_size',
|
||||
'type' => 'number',
|
||||
'priority' => 120,
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_description_font_weight', array(
|
||||
'default' => PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_form_description_font_weight_control', array(
|
||||
'label' => __( 'Font Weight', 'password-protect-page' ),
|
||||
'section' => self::GENERAL_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_description_font_weight',
|
||||
'type' => 'number',
|
||||
'priority' => 130,
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_description_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_TEXT_FONT_COLOR,
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_form_description_color_control', array(
|
||||
'label' => __( 'Text Color', 'password-protect-page' ),
|
||||
'section' => self::GENERAL_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_description_color',
|
||||
'priority' => 140,
|
||||
) )
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_desc_title' );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Title_Group_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_form_desc_title',
|
||||
array(
|
||||
'label' => __( 'Description Below Form', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_form',
|
||||
'settings' => 'ppwp_pcp_form_desc_title',
|
||||
'type' => 'control_title',
|
||||
'priority' => 145,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_description_below_form', array(
|
||||
'default' => PPW_Constants::DEFAULT_SHORTCODE_DESC_BELOW_PWD_FORM,
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Text_Editor_Custom_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_description_below_form', array(
|
||||
'label' => __( 'Description', 'password-protect-page' ),
|
||||
'section' => self::GENERAL_SECTION,
|
||||
'settings' => 'ppwp_pcp_description_below_form',
|
||||
'type' => 'textarea',
|
||||
'priority' => 146,
|
||||
)
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_description_below_form_font_size', array(
|
||||
'default' => PPW_Constants::DEFAULT_TEXT_FONT_SIZE,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_form_description_below_form_font_size_control', array(
|
||||
'label' => __( 'Font Size', 'password-protect-page' ),
|
||||
'description' => __( 'Font size in px', 'password-protect-page' ),
|
||||
'section' => self::GENERAL_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_description_below_form_font_size',
|
||||
'type' => 'number',
|
||||
'priority' => 147,
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_description_below_form_font_weight', array(
|
||||
'default' => PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_form_description_below_form_font_weight_control', array(
|
||||
'label' => __( 'Font Weight', 'password-protect-page' ),
|
||||
'section' => self::GENERAL_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_description_below_form_font_weight',
|
||||
'type' => 'number',
|
||||
'priority' => 148,
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_description_below_form_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_TEXT_FONT_COLOR,
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_form_description_below_form_color_control', array(
|
||||
'label' => __( 'Text Color', 'password-protect-page' ),
|
||||
'section' => self::GENERAL_SECTION,
|
||||
'settings' => 'ppwp_pcp_form_description_below_form_color',
|
||||
'priority' => 149,
|
||||
) )
|
||||
);
|
||||
|
||||
// $wp_customize->add_setting( 'ppwp_pcp_desc_above_btn' );
|
||||
// $wp_customize->add_control(
|
||||
// new PPW_Title_Group_Control(
|
||||
// $wp_customize,
|
||||
// 'ppwp_pcp_desc_above_btn',
|
||||
// array(
|
||||
// 'label' => __( 'Description Above Button', 'password-protect-page' ),
|
||||
// 'section' => 'ppwp_pcp_form',
|
||||
// 'settings' => 'ppwp_pcp_desc_above_btn',
|
||||
// 'type' => 'control_title',
|
||||
// 'priority' => 150,
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
|
||||
|
||||
// $wp_customize->add_setting( 'ppwp_pcp_description_above_btn', array(
|
||||
// 'default' => PPW_Constants::DEFAULT_SHORTCODE_DESC_ABOVE_PWD_BTN,
|
||||
// ) );
|
||||
// $wp_customize->add_control(
|
||||
// new PPW_Text_Editor_Custom_Control(
|
||||
// $wp_customize,
|
||||
// 'ppwp_pcp_description_above_btn',
|
||||
// array(
|
||||
// 'label' => __( 'Description', 'password-protect-page' ),
|
||||
// 'section' => self::GENERAL_SECTION,
|
||||
// 'settings' => 'ppwp_pcp_description_above_btn',
|
||||
// 'type' => 'textarea',
|
||||
// 'priority' => 152,
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
|
||||
// $wp_customize->add_setting( 'ppwp_pcp_form_description_above_btn_font_size', array(
|
||||
// 'default' => PPW_Constants::DEFAULT_TEXT_FONT_SIZE,
|
||||
// ) );
|
||||
// $wp_customize->add_control( 'ppwp_pcp_form_description_above_btn_font_size_control', array(
|
||||
// 'label' => __( 'Font Size', 'password-protect-page' ),
|
||||
// 'description' => __( 'Font size in px', 'password-protect-page' ),
|
||||
// 'section' => self::GENERAL_SECTION,
|
||||
// 'settings' => 'ppwp_pcp_form_description_above_btn_font_size',
|
||||
// 'type' => 'number',
|
||||
// 'priority' => 153,
|
||||
// ) );
|
||||
|
||||
// $wp_customize->add_setting( 'ppwp_pcp_form_description_above_btn_font_weight', array(
|
||||
// 'default' => PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT,
|
||||
// ) );
|
||||
// $wp_customize->add_control( 'ppwp_pcp_form_description_above_btn_font_weight_control', array(
|
||||
// 'label' => __( 'Font Weight', 'password-protect-page' ),
|
||||
// 'section' => self::GENERAL_SECTION,
|
||||
// 'settings' => 'ppwp_pcp_form_description_above_btn_font_weight',
|
||||
// 'type' => 'number',
|
||||
// 'priority' => 154,
|
||||
// ) );
|
||||
|
||||
// $wp_customize->add_setting( 'ppwp_pcp_form_description_above_btn_color', array(
|
||||
// 'default' => PPW_Constants::DEFAULT_TEXT_FONT_COLOR,
|
||||
// ) );
|
||||
// $wp_customize->add_control(
|
||||
// new \WP_Customize_Color_Control(
|
||||
// $wp_customize,
|
||||
// 'ppwp_pcp_form_description_above_btn_color_control', array(
|
||||
// 'label' => __( 'Text Color', 'password-protect-page' ),
|
||||
// 'section' => self::GENERAL_SECTION,
|
||||
// 'settings' => 'ppwp_pcp_form_description_above_btn_color',
|
||||
// 'priority' => 155,
|
||||
// ) )
|
||||
// );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_label_title' );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Title_Group_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_form_label_title',
|
||||
array(
|
||||
'label' => __( 'Password Field', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_form',
|
||||
'settings' => 'ppwp_pcp_form_label_title',
|
||||
'type' => 'control_title',
|
||||
'priority' => 159,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_label', array(
|
||||
'default' => PPW_Constants::DEFAULT_SHORTCODE_LABEL,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_form_label_control', array(
|
||||
'label' => __( 'Password Label', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_form',
|
||||
'settings' => 'ppwp_pcp_form_label',
|
||||
'type' => 'text',
|
||||
'priority' => 160,
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_label_font_size', array(
|
||||
'default' => PPW_Constants::DEFAULT_TEXT_FONT_SIZE,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_form_label_font_size_control', array(
|
||||
'label' => __( 'Font Size', 'password-protect-page' ),
|
||||
'description' => __( 'Font size in px', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_form',
|
||||
'settings' => 'ppwp_pcp_form_label_font_size',
|
||||
'type' => 'number',
|
||||
'priority' => 170,
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_label_font_weight', array(
|
||||
'default' => PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_form_label_font_weight_control', array(
|
||||
'label' => __( 'Font Weight', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_form',
|
||||
'settings' => 'ppwp_pcp_form_label_font_weight',
|
||||
'type' => 'number',
|
||||
'priority' => 180,
|
||||
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_label_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_TEXT_FONT_COLOR,
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_form_label_color_control', array(
|
||||
'label' => __( 'Text Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_form',
|
||||
'settings' => 'ppwp_pcp_form_label_color',
|
||||
'priority' => 190,
|
||||
) )
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_placeholder', array(
|
||||
'default' => PPW_Constants::DEFAULT_PLACEHOLDER,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_form_placeholder_control', array(
|
||||
'label' => __( 'Placeholder', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_form',
|
||||
'settings' => 'ppwp_pcp_form_placeholder',
|
||||
'type' => 'text',
|
||||
'priority' => 200,
|
||||
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_show_password_title' );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Title_Group_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_form_show_password_title', array(
|
||||
'label' => __( 'Show Password', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_form',
|
||||
'settings' => 'ppwp_pcp_form_show_password_title',
|
||||
'type' => 'control_title',
|
||||
'priority' => 210,
|
||||
) )
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_is_show_password', array(
|
||||
'default' => PPW_Constants::DEFAULT_SHORTCODE_SHOW_PASSWORD,
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Toggle_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_form_is_show_password_control', array(
|
||||
'label' => __( 'Show Password Reveal Button', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_form',
|
||||
'type' => 'toggle',
|
||||
'settings' => 'ppwp_pcp_form_is_show_password',
|
||||
'priority' => 220,
|
||||
) )
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_form_show_password_text', array(
|
||||
'default' => PPW_Constants::DEFAULT_SHORTCODE_SHOW_PASSWORD_TEXT,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_form_show_password_text_control', array(
|
||||
'label' => __( 'Button Text', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_form',
|
||||
'settings' => 'ppwp_pcp_form_show_password_text',
|
||||
'type' => 'text',
|
||||
'priority' => 230,
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Append error message section.
|
||||
*
|
||||
* @param WP_Customize $wp_customize WP Customize class.
|
||||
*/
|
||||
public function append_err_msg_section( $wp_customize ) {
|
||||
/* form error message section */
|
||||
$wp_customize->add_section( self::ERR_MSG_SECTION, array(
|
||||
'title' => __( 'Error Message', 'password-protect-page' ),
|
||||
'panel' => self::PANEL,
|
||||
'priority' => 20,
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_err_msg_text', array(
|
||||
'default' => PPW_Constants::DEFAULT_SHORTCODE_ERROR_MSG,
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Text_Editor_Custom_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_err_msg_text',
|
||||
array(
|
||||
'label' => __( 'Wrong Password Message', 'password-protect-page' ),
|
||||
'section' => self::ERR_MSG_SECTION,
|
||||
'settings' => 'ppwp_pcp_err_msg_text',
|
||||
'type' => 'textarea',
|
||||
'priority' => 10,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_err_msg_text_font_size', array(
|
||||
'default' => PPW_Constants::DEFAULT_ERROR_TEXT_FONT_SIZE,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_err_msg_text_font_size_control', array(
|
||||
'label' => __( 'Font Size', 'password-protect-page' ),
|
||||
'description' => __( 'Font size in px', 'password-protect-page' ),
|
||||
'section' => self::ERR_MSG_SECTION,
|
||||
'settings' => 'ppwp_pcp_err_msg_text_font_size',
|
||||
'type' => 'number',
|
||||
'priority' => 20,
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_err_msg_text_font_weight', array(
|
||||
'default' => PPW_Constants::DEFAULT_ERROR_TEXT_FONT_WEIGHT,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_err_msg_text_font_weight_control', array(
|
||||
'label' => __( 'Font Weight', 'password-protect-page' ),
|
||||
'section' => self::ERR_MSG_SECTION,
|
||||
'settings' => 'ppwp_pcp_err_msg_text_font_weight',
|
||||
'type' => 'number',
|
||||
'priority' => 25,
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_err_msg_text_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_ERROR_TEXT_FONT_COLOR,
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_err_msg_text_color_control', array(
|
||||
'label' => __( 'Text Color', 'password-protect-page' ),
|
||||
'section' => self::ERR_MSG_SECTION,
|
||||
'settings' => 'ppwp_pcp_err_msg_text_color',
|
||||
'priority' => 30,
|
||||
) )
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_err_msg_background_color', array(
|
||||
'default' => '#ffffff',
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_err_msg_background_color_control', array(
|
||||
'label' => __( 'Background Color', 'password-protect-page' ),
|
||||
'section' => self::ERR_MSG_SECTION,
|
||||
'settings' => 'ppwp_pcp_err_msg_background_color',
|
||||
'priority' => 35,
|
||||
) )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append button section.
|
||||
*
|
||||
* @param WP_Customize $wp_customize WP Customize class.
|
||||
*/
|
||||
public function append_button_section( $wp_customize ) {
|
||||
$wp_customize->add_section( self::BUTTON_SECTION, array(
|
||||
'title' => __( 'Button', 'password-protect-page' ),
|
||||
'panel' => self::PANEL,
|
||||
'priority' => 300,
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_button_text', array(
|
||||
'default' => PPW_Constants::DEFAULT_SHORTCODE_BUTTON,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_button_text_control', array(
|
||||
'label' => __( 'Button Label', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_button',
|
||||
'settings' => 'ppwp_pcp_button_text',
|
||||
'type' => 'text',
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_button_loading_text', array(
|
||||
'default' => __( PPW_Constants::DEFAULT_SHORTCODE_LOADING, 'password-protect-page' ),
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pcp_button_loading_text_control', array(
|
||||
'label' => __( 'Button Loading Label', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_button',
|
||||
'settings' => 'ppwp_pcp_button_loading_text',
|
||||
'type' => 'text',
|
||||
) );
|
||||
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_button_text_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_BUTTON_TEXT_FONT_COLOR,
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_button_text_color_control', array(
|
||||
'label' => __( 'Text Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_button',
|
||||
'settings' => 'ppwp_pcp_button_text_color',
|
||||
) )
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_button_text_hover_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_BUTTON_TEXT_HOVER_COLOR,
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_button_text_hover_color_control', array(
|
||||
'label' => __( 'Text Color (Hover)', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_button',
|
||||
'settings' => 'ppwp_pcp_button_text_hover_color',
|
||||
) )
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_button_background_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_BUTTON_BACKGROUND_COLOR,
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_button_background_color_control', array(
|
||||
'label' => __( 'Background Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_button',
|
||||
'settings' => 'ppwp_pcp_button_background_color',
|
||||
) )
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_pcp_button_background_hover_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_BUTTON_BACKGROUND_HOVER_COLOR,
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pcp_button_background_hover_color_control', array(
|
||||
'label' => __( 'Background Color (Hover)', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pcp_button',
|
||||
'settings' => 'ppwp_pcp_button_background_hover_color',
|
||||
) )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add dynamic styles
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dynamic_styles() {
|
||||
$ppw_custom_css = "
|
||||
<style>
|
||||
.ppw-form {
|
||||
background-color: " . get_theme_mod( 'ppwp_pcp_form_background_color', PPW_Constants::DEFAULT_FORM_BACKGROUND_COLOR ) . "!important;
|
||||
padding: " . get_theme_mod( 'ppwp_pcp_form_padding', PPW_Constants::DEFAULT_FORM_PADDING ) . "px!important;
|
||||
border-radius: " . get_theme_mod( 'ppwp_pcp_form_border_radius', PPW_Constants::DEFAULT_FORM_BORDER_RADIUS ) . "px!important;
|
||||
}
|
||||
|
||||
.ppw-headline.ppw-pcp-pf-headline {
|
||||
font-size: " . get_theme_mod( 'ppwp_pcp_form_headline_font_size', PPW_Constants::DEFAULT_HEADLINE_FONT_SIZE ) . "px!important;
|
||||
font-weight: " . get_theme_mod( 'ppwp_pcp_form_headline_font_weight', PPW_Constants::DEFAULT_HEADLINE_FONT_WEIGHT ) . "!important;
|
||||
color: " . get_theme_mod( 'ppwp_pcp_form_headline_color', PPW_Constants::DEFAULT_HEADLINE_FONT_COLOR ) . "!important;
|
||||
}
|
||||
|
||||
.ppw-description.ppw-pcp-pf-desc {
|
||||
font-size: " . get_theme_mod( 'ppwp_pcp_form_description_font_size', PPW_Constants::DEFAULT_TEXT_FONT_SIZE ) . "px!important;
|
||||
font-weight: " . get_theme_mod( 'ppwp_pcp_form_description_font_weight', PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT ) . "!important;
|
||||
color: " . get_theme_mod( 'ppwp_pcp_form_description_color', PPW_Constants::DEFAULT_TEXT_FONT_COLOR ) . "!important;
|
||||
}
|
||||
|
||||
.ppw-pcp-pf-desc-above-btn {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.ppw-pcp-pf-desc-below-form {
|
||||
font-size: " . get_theme_mod( 'ppwp_pcp_form_description_below_form_font_size', PPW_Constants::DEFAULT_TEXT_FONT_SIZE ) . "px!important;
|
||||
font-weight: " . get_theme_mod( 'ppwp_pcp_form_description_below_form_font_weight', PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT ) . "!important;
|
||||
color: " . get_theme_mod( 'ppwp_pcp_form_description_below_form_color', PPW_Constants::DEFAULT_TEXT_FONT_COLOR ) . "!important;
|
||||
}
|
||||
|
||||
.ppw-input label.ppw-pcp-password-label {
|
||||
font-size: " . get_theme_mod( 'ppwp_pcp_form_label_font_size', PPW_Constants::DEFAULT_TEXT_FONT_SIZE ) . "px!important;
|
||||
font-weight: " . get_theme_mod( 'ppwp_pcp_form_label_font_weight', PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT ) . "!important;
|
||||
color: " . get_theme_mod( 'ppwp_pcp_form_label_color', PPW_Constants::DEFAULT_TEXT_FONT_COLOR ) . "!important;
|
||||
}
|
||||
|
||||
.ppw-form input[type='submit'] {
|
||||
color: " . get_theme_mod( 'ppwp_pcp_button_text_color', PPW_Constants::DEFAULT_BUTTON_TEXT_FONT_COLOR ) . "!important;
|
||||
background: " . get_theme_mod( 'ppwp_pcp_button_background_color', PPW_Constants::DEFAULT_BUTTON_BACKGROUND_COLOR ) . "!important;
|
||||
}
|
||||
|
||||
.ppw-form input[type='submit']:hover {
|
||||
color: " . get_theme_mod( 'ppwp_pcp_button_text_hover_color', PPW_Constants::DEFAULT_BUTTON_TEXT_HOVER_COLOR ) . "!important;
|
||||
background: " . get_theme_mod( 'ppwp_pcp_button_background_hover_color', PPW_Constants::DEFAULT_BUTTON_BACKGROUND_HOVER_COLOR ) . "!important;
|
||||
}
|
||||
|
||||
div.ppw-error.ppw-pcp-pf-error-msg {
|
||||
font-size: " . get_theme_mod( 'ppwp_pcp_err_msg_text_font_size', PPW_Constants::DEFAULT_ERROR_TEXT_FONT_SIZE ) . "px!important;
|
||||
font-weight: " . get_theme_mod( 'ppwp_pcp_err_msg_text_font_weight', PPW_Constants::DEFAULT_ERROR_TEXT_FONT_WEIGHT ) . "!important;
|
||||
color: " . get_theme_mod( 'ppwp_pcp_err_msg_text_color', PPW_Constants::DEFAULT_ERROR_TEXT_FONT_COLOR ) . "!important;
|
||||
background: " . get_theme_mod( 'ppwp_pcp_err_msg_background_color', PPW_Constants::DEFAULT_ERROR_TEXT_BACKGROUND_COLOR ) . "!important;
|
||||
}
|
||||
|
||||
</style>
|
||||
";
|
||||
|
||||
// compress $ppw_custom_css.
|
||||
$ppw_custom_css = preg_replace( "/\s{2,}/", " ", str_replace( "\n", "", str_replace( ', ', ",", $ppw_custom_css ) ) );
|
||||
|
||||
echo $ppw_custom_css;
|
||||
}
|
||||
|
||||
/*
|
||||
* Optimize css.
|
||||
*/
|
||||
public function optimize_css( $sw_custom_css ) {
|
||||
return preg_replace( "/\s{2,}/", " ", str_replace( "\n", "", str_replace( ', ', ",", $sw_custom_css ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,440 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'PPW_Customizer_Sitewide' ) ) {
|
||||
// TODO: need to force PPW_Pro_Customizer_Service extend this class to remove the code duplication.
|
||||
class PPW_Customizer_Sitewide {
|
||||
|
||||
/**
|
||||
* Instance of PPW_Pro_Shortcode class.
|
||||
*
|
||||
* @var PPW_Customizer_Sitewide
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
public function register_sitewide_form() {
|
||||
add_action( 'customize_register', array( $this, 'customize_register' ), 15 );
|
||||
}
|
||||
|
||||
public static function register_themes() {
|
||||
$self = new self();
|
||||
add_action( 'customize_register', array( $self, 'customize_register_themes' ), 25 );
|
||||
add_action( 'ppw_custom_style_form_entire_site', array( $self, 'load_css_to_pro' ), 15 );
|
||||
}
|
||||
|
||||
public function register_sitewide_style() {
|
||||
add_action( PPW_Constants::HOOK_CUSTOM_STYLE_FORM_ENTIRE_SITE, array( $this, 'dynamic_styles' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $wp_customize
|
||||
*/
|
||||
public function customize_register_themes( $wp_customize ) {
|
||||
if ( ! class_exists( 'PPW_Presets_Control' ) ) {
|
||||
include PPW_DIR_PATH . 'includes/customizers/class-ppw-presets.php';
|
||||
}
|
||||
|
||||
$wp_customize->add_section( 'ppw_customize_presets', array(
|
||||
'title' => __( 'Themes', 'password-protect-page' ),
|
||||
'panel' => 'ppwp_sitewide',
|
||||
'priority' => 50,
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppw_customize_presets_settings', array(
|
||||
'default' => 'default0',
|
||||
'capability' => 'edit_theme_options',
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new PPW_Presets_Control( $wp_customize, 'ppw_customize_presets_settings',
|
||||
array(
|
||||
'section' => 'ppw_customize_presets',
|
||||
// 'label' => __( 'Themes', 'loginpress' ),
|
||||
'choices' => $this->get_templates(),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get instance of PPW_Customizer
|
||||
*
|
||||
* @return PPW_Customizer_Sitewide
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( is_null( self::$instance ) ) {
|
||||
// Use static instead of self due to the inheritance later.
|
||||
// For example: ChildSC extends this class, when we call get_instance
|
||||
// it will return the object of child class. On the other hand, self function
|
||||
// will return the object of base class.
|
||||
self::$instance = new static();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register customizer fields
|
||||
*
|
||||
* @param object $wp_customize customizer object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
if ( ! class_exists( 'PPW_Toggle_Control' ) ) {
|
||||
include PPW_DIR_PATH . 'includes/customizers/class-ppw-title-group-control.php';
|
||||
}
|
||||
if ( ! class_exists( 'PPW_Title_Group_Control' ) ) {
|
||||
include PPW_DIR_PATH . 'includes/customizers/class-ppw-toggle-control.php';
|
||||
}
|
||||
|
||||
/* register toggle control */
|
||||
$wp_customize->register_control_type( 'PPW_Toggle_Control' );
|
||||
$wp_customize->register_control_type( 'PPW_Title_Group_Control' );
|
||||
|
||||
$wp_customize->add_panel( 'ppwp_sitewide',
|
||||
array(
|
||||
'priority' => 9980,
|
||||
'capability' => 'edit_theme_options',
|
||||
'theme_supports' => '',
|
||||
'title' => __( 'PPWP Sitewide Login Form', 'password-protect-page' ),
|
||||
)
|
||||
);
|
||||
|
||||
/* form logo section */
|
||||
$wp_customize->add_section( 'ppwp_pro_form_logo', array(
|
||||
'title' => __( 'Logo', 'password-protect-page' ),
|
||||
'panel' => 'ppwp_sitewide',
|
||||
'priority' => 100,
|
||||
) );
|
||||
|
||||
// Add an option to disable the logo.
|
||||
$wp_customize->add_setting( 'ppwp_pro_logo_disable' );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Toggle_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pro_logo_disable_control', array(
|
||||
'label' => __( 'Disable Logo', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_logo',
|
||||
'type' => 'toggle',
|
||||
'settings' => 'ppwp_pro_logo_disable',
|
||||
) )
|
||||
);
|
||||
|
||||
/* logo customize */
|
||||
$wp_customize->add_setting( 'ppwp_pro_logo_customize', array(
|
||||
'default' => __( PPW_DIR_URL . 'includes/views/entire-site/assets/ppwp-logo.png', 'password-protect-page' ),
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Image_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pro_logo_customize_control', array(
|
||||
'label' => __( 'Logo Image', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_logo',
|
||||
'settings' => 'ppwp_pro_logo_customize',
|
||||
) )
|
||||
);
|
||||
|
||||
/* logo width */
|
||||
$wp_customize->add_setting( 'ppwp_pro_logo_customize_width' );
|
||||
$wp_customize->add_control( 'ppwp_pro_logo_customize_width_control', array(
|
||||
'label' => __( 'Logo Width', 'password-protect-page' ),
|
||||
'description' => __( 'Width in px', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_logo',
|
||||
'settings' => 'ppwp_pro_logo_customize_width',
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
/* logo height */
|
||||
$wp_customize->add_setting( 'ppwp_pro_logo_customize_height' );
|
||||
$wp_customize->add_control( 'ppwp_pro_logo_customize_height_control', array(
|
||||
'label' => __( 'Logo Height', 'password-protect-page' ),
|
||||
'description' => __( 'Height in px', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_logo',
|
||||
'settings' => 'ppwp_pro_logo_customize_height',
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
/* logo border-radius */
|
||||
$wp_customize->add_setting( 'ppwp_pro_logo_customize_border_radius' );
|
||||
$wp_customize->add_control( 'ppwp_pro_logo_customize_border_radius_control', array(
|
||||
'label' => __( 'Logo Radius', 'password-protect-page' ),
|
||||
'description' => __( 'Border Radius in %', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_logo',
|
||||
'settings' => 'ppwp_pro_logo_customize_border_radius',
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
/* password form section */
|
||||
$wp_customize->add_section( 'ppwp_pro_form_instructions', array(
|
||||
'title' => __( 'Password Form', 'password-protect-page' ),
|
||||
'panel' => 'ppwp_sitewide',
|
||||
'priority' => 300,
|
||||
) );
|
||||
|
||||
/* form section group */
|
||||
$wp_customize->add_setting( 'ppwp_pro_form_section_group' );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Title_Group_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pro_form_section_group', array(
|
||||
'label' => __( 'Password Form', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_instructions',
|
||||
'settings' => 'ppwp_pro_form_section_group',
|
||||
'type' => 'control_title',
|
||||
) )
|
||||
);
|
||||
|
||||
/* form countdown section */
|
||||
|
||||
apply_filters('ppwp_customizer_custom_fields', $wp_customize, $wp_customize);
|
||||
|
||||
/* enable form transparency */
|
||||
$wp_customize->add_setting( 'ppwp_pro_form_enable_transparency' );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Toggle_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pro_form_enable_transparency_control', array(
|
||||
'label' => __( 'Enable Form Transparency', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_instructions',
|
||||
'type' => 'toggle',
|
||||
'settings' => 'ppwp_pro_form_enable_transparency',
|
||||
) )
|
||||
);
|
||||
|
||||
/* password form background color */
|
||||
$wp_customize->add_setting( 'ppwp_pro_form_instructions_background_color', array(
|
||||
'default' => '',
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pro_form_instructions_background_color_control', array(
|
||||
'label' => __( 'Form Background Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_instructions',
|
||||
'settings' => 'ppwp_pro_form_instructions_background_color',
|
||||
) )
|
||||
);
|
||||
|
||||
/* password form width */
|
||||
$wp_customize->add_setting( 'ppwp_pro_form_instructions_width' );
|
||||
$wp_customize->add_control( 'ppwp_pro_form_instructions_width_control', array(
|
||||
'label' => __( 'Form Width', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_instructions',
|
||||
'settings' => 'ppwp_pro_form_instructions_width',
|
||||
'description' => 'Width in px',
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
/* password form border radius */
|
||||
$wp_customize->add_setting( 'ppwp_pro_form_instructions_border_radius' );
|
||||
$wp_customize->add_control( 'ppwp_pro_form_instructions_border_radius_control', array(
|
||||
'label' => __( 'Form Border Radius', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_instructions',
|
||||
'settings' => 'ppwp_pro_form_instructions_border_radius',
|
||||
'description' => 'Border Radius in px',
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
/* password label group */
|
||||
$wp_customize->add_setting( 'ppwp_pro_password_label_group' );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Title_Group_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pro_password_label_group', array(
|
||||
'label' => __( 'Password Field', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_instructions',
|
||||
'settings' => 'ppwp_pro_password_label_group',
|
||||
'type' => 'control_title',
|
||||
) )
|
||||
);
|
||||
|
||||
/* password label font size */
|
||||
$wp_customize->add_setting( 'ppwp_pro_form_instructions_password_label_font_size' );
|
||||
$wp_customize->add_control( 'ppwp_pro_form_instructions_password_label_font_size_control', array(
|
||||
'label' => __( 'Font Size', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_instructions',
|
||||
'settings' => 'ppwp_pro_form_instructions_password_label_font_size',
|
||||
'description' => __( 'Font size in px', 'password-protect-page' ),
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
/* password label color */
|
||||
$wp_customize->add_setting( 'ppwp_pro_form_instructions_password_label_color' );
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pro_form_instructions_password_label_color_control', array(
|
||||
'label' => __( 'Label Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_instructions',
|
||||
'settings' => 'ppwp_pro_form_instructions_password_label_color',
|
||||
) )
|
||||
);
|
||||
|
||||
/* placeholder text */
|
||||
$wp_customize->add_setting( 'ppwp_pro_form_instructions_placeholder' );
|
||||
$wp_customize->add_control( 'ppwp_pro_form_instructions_placeholder_control', array(
|
||||
'label' => __( 'Placeholder', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_instructions',
|
||||
'settings' => 'ppwp_pro_form_instructions_placeholder',
|
||||
'type' => 'text',
|
||||
) );
|
||||
|
||||
/* form button section */
|
||||
$wp_customize->add_section( 'ppwp_pro_form_button', array(
|
||||
'title' => __( 'Button', 'password-protect-page' ),
|
||||
'panel' => 'ppwp_sitewide',
|
||||
'priority' => 400,
|
||||
) );
|
||||
|
||||
/* button label */
|
||||
$wp_customize->add_setting( 'ppwp_pro_form_button_label', array(
|
||||
'default' => __( 'Enter', 'password-protect-page' ),
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_pro_form_button_label_control', array(
|
||||
'label' => __( 'Button Label', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_button',
|
||||
'settings' => 'ppwp_pro_form_button_label',
|
||||
'type' => 'text',
|
||||
) );
|
||||
|
||||
/* button text color */
|
||||
$wp_customize->add_setting( 'ppwp_pro_form_button_text_color' );
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pro_form_button_text_color_control', array(
|
||||
'label' => __( 'Text Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_button',
|
||||
'settings' => 'ppwp_pro_form_button_text_color',
|
||||
) )
|
||||
);
|
||||
|
||||
/* button background color */
|
||||
$wp_customize->add_setting( 'ppwp_pro_form_button_background_color' );
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_pro_form_button_background_color_control', array(
|
||||
'label' => __( 'Background Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_pro_form_button',
|
||||
'settings' => 'ppwp_pro_form_button_background_color',
|
||||
) )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add dynamic styles
|
||||
*
|
||||
* TODO: move this styles into css file.
|
||||
* @return void
|
||||
*/
|
||||
public function dynamic_styles() {
|
||||
$sw_custom_css = $this->get_preset_css();
|
||||
$sw_custom_css = $sw_custom_css . '
|
||||
.pda-form-login {
|
||||
width: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_instructions_width' ) ) . 'px!important;
|
||||
}
|
||||
|
||||
.pda-form-login label {
|
||||
font-size: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_instructions_password_label_font_size' ) ) . 'px!important;
|
||||
color: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_instructions_password_label_color' ) ) . '!important;
|
||||
}
|
||||
|
||||
.pda-form-login form {
|
||||
background-color: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_instructions_background_color' ) ) . '!important;
|
||||
border-radius: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_instructions_border_radius' ) ) . 'px!important;
|
||||
}
|
||||
|
||||
.pda-form-login a.ppw-swp-logo {
|
||||
background-image: none, url(' . esc_url( get_theme_mod( 'ppwp_pro_logo_customize', PPW_DIR_URL . 'includes/views/entire-site/assets/ppwp-logo.png' ) ) . ')!important;
|
||||
background-size: cover;
|
||||
width: ' . esc_attr( get_theme_mod( 'ppwp_pro_logo_customize_width', '' ) ) . 'px!important;
|
||||
height: ' . esc_attr( get_theme_mod( 'ppwp_pro_logo_customize_height', '' ) ) . 'px!important;
|
||||
border-radius: ' . esc_attr( get_theme_mod( 'ppwp_pro_logo_customize_border_radius', '' ) ) . '%!important;
|
||||
}
|
||||
|
||||
.pda-form-login .button-login {
|
||||
color: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_button_text_color' ) ) . '!important;
|
||||
background-color: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_button_background_color' ) ) . '!important;
|
||||
border-color: ' . esc_attr( get_theme_mod( 'ppwp_pro_form_button_background_color' ) ) . '!important;
|
||||
}
|
||||
';
|
||||
|
||||
// remove space in $sw_custom_css.
|
||||
$sw_custom_css = $this->optimize_css( $sw_custom_css );
|
||||
echo $sw_custom_css; // phpcs:ignore -- we already escase inside the css
|
||||
}
|
||||
|
||||
/*
|
||||
* Optimize css.
|
||||
*/
|
||||
public function optimize_css( $sw_custom_css ) {
|
||||
return preg_replace( "/\s{2,}/", " ", str_replace( "\n", "", str_replace( ', ', ",", $sw_custom_css ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get templates.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_templates() {
|
||||
$free_templates = array();
|
||||
$themes_name = array(
|
||||
__( 'Default', 'password-protect-page' ),
|
||||
__( 'Event', 'password-protect-page' ),
|
||||
__( 'Business', 'password-protect-page' ),
|
||||
__( 'Wedding', 'password-protect-page' ),
|
||||
);
|
||||
|
||||
foreach ( $themes_name as $index => $theme_name ) {
|
||||
$free_templates["default{$index}"] = array(
|
||||
'thumbnail' => PPW_DIR_URL . 'includes/customizers/assets/images/thumbnail/sw-default' . $index . '.png',
|
||||
'id' => "default{$index}",
|
||||
'name' => $theme_name,
|
||||
'css_file' => PPW_DIR_PATH . 'includes/customizers/assets/css/sw-default' . $index . '.php',
|
||||
);
|
||||
}
|
||||
|
||||
return apply_filters( 'ppw_customizer_sitewide_templates', $free_templates );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get css of a theme.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_preset_css() {
|
||||
$default_preset = 'default0';
|
||||
$preset = esc_attr( get_theme_mod( 'ppw_customize_presets_settings', $default_preset ) );
|
||||
$sw_custom_css = '';
|
||||
if ( $preset !== $default_preset ) {
|
||||
$templates = $this->get_templates();
|
||||
if ( isset( $templates[ $preset ], $templates[ $preset ]['css_file'] ) ) {
|
||||
ob_start();
|
||||
include_once( $templates[ $preset ]['css_file'] );
|
||||
?>
|
||||
@media screen and (max-width: 768px) {
|
||||
.pda-form-login {
|
||||
width: 100%;
|
||||
}
|
||||
.pda-form-login form {
|
||||
width: 90%;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
$sw_custom_css = ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
return $sw_custom_css;
|
||||
}
|
||||
|
||||
public function load_css_to_pro() {
|
||||
echo $this->optimize_css( $this->get_preset_css() ); // phpcs:ignores -- we don't need to escape css, already escape $preset above
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'PPW_Customizer_Upsell' ) ) {
|
||||
|
||||
/**
|
||||
* Register PPW_Customizer_Upsell Configurations.
|
||||
*/
|
||||
class PPW_Customizer_Upsell {
|
||||
|
||||
/**
|
||||
* Register upsell section for customize
|
||||
*
|
||||
* @var PPW_Customizer_Upsell
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for PPW_Customizer_Upsell
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'customize_register', array( $this, 'customize_register' ) );
|
||||
add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get instance of PPW_Customizer_Upsell
|
||||
*
|
||||
* @return PPW_Customizer_Upsell
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( is_null( self::$instance ) ) {
|
||||
self::$instance = new static();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function customize_register( $wp_customize ) {
|
||||
include PPW_DIR_PATH . 'includes/customizers/class-ppw-customize-link-section.php';
|
||||
|
||||
$wp_customize->register_section_type( 'PPW_Customize_Link_Section' );
|
||||
|
||||
$wp_customize->add_section(
|
||||
new PPW_Customize_Link_Section( $wp_customize, 'ppwp_upsell',
|
||||
array(
|
||||
'ppwp_text' => __( 'More options available in PPWP Pro', 'password-protect-page' ),
|
||||
'ppwp_url' => esc_url( 'https://passwordprotectwp.com/features/lite-vs-pro-version/?utm_source=user-website&utm_medium=wp-customizer&utm_campaign=ppwp-free#sitewide-customizer' ),
|
||||
'capability' => 'edit_theme_options',
|
||||
'priority' => 9999,
|
||||
'type' => 'ppwp-upsell-section',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function enqueue() {
|
||||
wp_enqueue_script( 'ppw-upsell-section-scripts', PPW_DIR_URL . 'includes/customizers/assets/ppw-upsell-section.js', array( 'jquery' ), PPW_VERSION, true );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,749 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'PPW_Customizer_Service' ) ) {
|
||||
class PPW_Customizer_Service {
|
||||
|
||||
/**
|
||||
* Instance of PPW_Pro_Shortcode class.
|
||||
*
|
||||
* @var PPW_Customizer_Service
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* Constructor for PPW_Customizer
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'customize_register', array( $this, 'customize_register' ) );
|
||||
add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue' ) );
|
||||
add_action( 'wp_head', array( $this, 'dynamic_styles' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get instance of PPW_Customizer
|
||||
*
|
||||
* @return PPW_Customizer_Service
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( is_null( self::$instance ) ) {
|
||||
// Use static instead of self due to the inheritance later.
|
||||
// For example: ChildSC extends this class, when we call get_instance
|
||||
// it will return the object of child class. On the other hand, self function
|
||||
// will return the object of base class.
|
||||
self::$instance = new static();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get below text style.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_below_text_style() {
|
||||
if ( defined( 'PPW_PRO_VERSION' ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$desc_font_size = get_theme_mod( 'ppwp_form_instructions_below_text_font_size' );
|
||||
$desc_font_weight = get_theme_mod( 'ppwp_form_instructions_below_text_font_weight' );
|
||||
$desc_color = get_theme_mod( 'ppwp_form_instructions_below_text_color' );
|
||||
|
||||
$customizer_style = "
|
||||
.ppw-ppf-desc-below {
|
||||
font-size: " . $desc_font_size . "px!important;
|
||||
font-weight: " . $desc_font_weight . "!important;
|
||||
color: " . $desc_color . "!important;
|
||||
}
|
||||
";
|
||||
|
||||
return $customizer_style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add below description customize.
|
||||
*
|
||||
* @param $wp_customize
|
||||
*/
|
||||
public function add_below_desc( $wp_customize ) {
|
||||
if ( defined( 'PPW_PRO_VERSION' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_description_below_title' );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new PPW_Title_Group_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_instructions_description_below_title',
|
||||
array(
|
||||
'label' => __( 'Description Below Form', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_description_below_title',
|
||||
'type' => 'control_title',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
/* instructions text */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_below_text' );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new PPW_Text_Editor_Custom_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_instructions_below_text',
|
||||
array(
|
||||
'label' => __( 'Description', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_below_text',
|
||||
'type' => 'textarea',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
/* instructions font size */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_below_text_font_size' );
|
||||
|
||||
$wp_customize->add_control(
|
||||
'ppwp_form_instructions_below_text_font_size_control',
|
||||
array(
|
||||
'label' => __( 'Font Size', 'password-protect-page' ),
|
||||
'description' => __( 'Font size in px', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_below_text_font_size',
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
/* instructions font weight */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_below_text_font_weight' );
|
||||
|
||||
$wp_customize->add_control(
|
||||
'ppwp_form_instructions_below_text_font_weight_control',
|
||||
array(
|
||||
'label' => __( 'Font Weight', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_below_text_font_weight',
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
/* text color - form instructions */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_below_text_color' );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_instructions_below_text_color_control',
|
||||
array(
|
||||
'label' => __( 'Text Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_below_text_color',
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register customizer fields
|
||||
*
|
||||
* @param object $wp_customize customizer object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function customize_register( $wp_customize ) {
|
||||
if ( ! class_exists( 'PPW_Title_Group_Control' ) ) {
|
||||
include PPW_DIR_PATH . 'includes/customizers/class-ppw-title-group-control.php';
|
||||
}
|
||||
if ( ! class_exists( 'PPW_Toggle_Control' ) ) {
|
||||
include PPW_DIR_PATH . 'includes/customizers/class-ppw-toggle-control.php';
|
||||
}
|
||||
if ( ! class_exists( 'PPW_Text_Editor_Custom_Control' ) ) {
|
||||
include PPW_DIR_PATH . 'includes/customizers/class-ppw-text-editor-control.php';
|
||||
}
|
||||
|
||||
/* register toggle control */
|
||||
$wp_customize->register_control_type( 'PPW_Toggle_Control' );
|
||||
$wp_customize->register_control_type( 'PPW_Title_Group_Control' );
|
||||
$wp_customize->register_control_type( 'PPW_Text_Editor_Custom_Control' );
|
||||
|
||||
$wp_customize->add_panel( 'ppwp',
|
||||
array(
|
||||
'priority' => 9970,
|
||||
'capability' => 'edit_theme_options',
|
||||
'theme_supports' => '',
|
||||
'title' => __( 'PPWP Single Password Form', 'password-protect-page' ),
|
||||
)
|
||||
);
|
||||
|
||||
/* form instructions section */
|
||||
$wp_customize->add_section( 'ppwp_form_instructions', array(
|
||||
'title' => __( 'Password Form', 'password-protect-page' ),
|
||||
'panel' => 'ppwp',
|
||||
'priority' => 100,
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_background_title' );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new PPW_Title_Group_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_instructions_background_title', array(
|
||||
'label' => __( 'Background', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_background_title',
|
||||
'type' => 'control_title',
|
||||
) )
|
||||
);
|
||||
|
||||
/* form background color */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_background_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_FORM_BACKGROUND_COLOR,
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_instructions_background_color_control', array(
|
||||
'label' => __( 'Background Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_background_color',
|
||||
) )
|
||||
);
|
||||
|
||||
/* form background padding */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_padding', array(
|
||||
'default' => PPW_Constants::DEFAULT_FORM_PADDING,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_form_instructions_padding_control', array(
|
||||
'label' => __( 'Padding', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'description' => 'Padding in px',
|
||||
'settings' => 'ppwp_form_instructions_padding',
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
/* form background border radius */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_border_radius', array(
|
||||
'default' => PPW_Constants::DEFAULT_FORM_BORDER_RADIUS,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_form_instructions_border_radius_control', array(
|
||||
'label' => __( 'Border Radius', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'description' => 'Border Radius in px',
|
||||
'settings' => 'ppwp_form_instructions_border_radius',
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_headline_title' );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new PPW_Title_Group_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_instructions_headline_title', array(
|
||||
'label' => __( 'Headline', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_headline_title',
|
||||
'type' => 'control_title',
|
||||
) )
|
||||
);
|
||||
|
||||
/* instructions headline */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_headline', array(
|
||||
'default' => __( PPW_Constants::DEFAULT_HEADLINE_TEXT, 'password-protect-page' ),
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Text_Editor_Custom_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_instructions_headline',
|
||||
array(
|
||||
'label' => __( 'Headline', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_headline',
|
||||
'type' => 'textarea',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
/* headline font size */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_headline_font_size', array(
|
||||
'default' => PPW_Constants::DEFAULT_HEADLINE_FONT_SIZE,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_form_instructions_headline_font_size_control', array(
|
||||
'label' => __( 'Font Size', 'password-protect-page' ),
|
||||
'description' => __( 'Font size in px', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_headline_font_size',
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
/* headline font weight */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_headline_font_weight', array(
|
||||
'default' => PPW_Constants::DEFAULT_HEADLINE_FONT_WEIGHT,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_form_instructions_headline_font_weight_control', array(
|
||||
'label' => __( 'Font Weight', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_headline_font_weight',
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
/* headline color */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_headline_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_HEADLINE_FONT_COLOR,
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_instructions_headline_color_control', array(
|
||||
'label' => __( 'Text Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_headline_color',
|
||||
) )
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_description_title' );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new PPW_Title_Group_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_instructions_description_title', array(
|
||||
'label' => __( 'Description Above Form', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_description_title',
|
||||
'type' => 'control_title',
|
||||
) )
|
||||
);
|
||||
|
||||
/* instructions text */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_text', array(
|
||||
'default' => __( apply_filters( PPW_Constants::HOOK_MESSAGE_PASSWORD_FORM, PPW_Constants::DEFAULT_FORM_MESSAGE ), 'password-protect-page' ),
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new PPW_Text_Editor_Custom_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_instructions_text',
|
||||
array(
|
||||
'label' => __( 'Description', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_text',
|
||||
'type' => 'textarea',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
/* instructions font size */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_text_font_size', array(
|
||||
'default' => PPW_Constants::DEFAULT_TEXT_FONT_SIZE,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_form_instructions_text_font_size_control', array(
|
||||
'label' => __( 'Font Size', 'password-protect-page' ),
|
||||
'description' => __( 'Font size in px', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_text_font_size',
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
/* instructions font weight */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_text_font_weight', array(
|
||||
'default' => PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_form_instructions_text_font_weight_control', array(
|
||||
'label' => __( 'Font Weight', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_text_font_weight',
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
/* text color - form instructions */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_text_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_TEXT_FONT_COLOR,
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_instructions_text_color_control', array(
|
||||
'label' => __( 'Text Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_text_color',
|
||||
) )
|
||||
);
|
||||
|
||||
$this->add_below_desc( $wp_customize );
|
||||
|
||||
// Add one more tab below "Description Text Color" control.
|
||||
do_action( 'ppw_customize_after_text_color', $wp_customize );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_label_title' );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Title_Group_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_instructions_label_title', array(
|
||||
'label' => __( 'Password Field', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_label_title',
|
||||
'type' => 'control_title',
|
||||
) )
|
||||
);
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_password_label', array(
|
||||
'default' => PPW_Constants::DEFAULT_PASSWORD_LABEL,
|
||||
) );
|
||||
|
||||
$wp_customize->add_control( 'ppwp_form_instructions_password_label_control', array(
|
||||
'label' => __( 'Password Label', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_password_label',
|
||||
'type' => 'text',
|
||||
) );
|
||||
|
||||
/* instructions font size */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_password_label_font_size', array(
|
||||
'default' => PPW_Constants::DEFAULT_TEXT_FONT_SIZE,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_form_instructions_password_label_font_size_control', array(
|
||||
'label' => __( 'Font Size', 'password-protect-page' ),
|
||||
'description' => __( 'Font size in px', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_password_label_font_size',
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
/* instructions font weight */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_password_label_font_weight', array(
|
||||
'default' => PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_form_instructions_password_label_font_weight_control', array(
|
||||
'label' => __( 'Font Weight', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_password_label_font_weight',
|
||||
'type' => 'number',
|
||||
) );
|
||||
|
||||
/* text color - form instructions */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_password_label_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_TEXT_FONT_COLOR,
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_instructions_password_label_color_control', array(
|
||||
'label' => __( 'Text Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_password_label_color',
|
||||
) )
|
||||
);
|
||||
|
||||
/* placeholder text */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_placeholder', array(
|
||||
'default' => __( PPW_Constants::DEFAULT_PLACEHOLDER, 'password-protect-page' ),
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_form_instructions_placeholder_control', array(
|
||||
'label' => __( 'Placeholder', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_placeholder',
|
||||
'type' => 'text',
|
||||
) );
|
||||
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_show_password_title' );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Title_Group_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_instructions_show_password_title', array(
|
||||
'label' => __( 'Show Password', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_show_password_title',
|
||||
'type' => 'control_title',
|
||||
) )
|
||||
);
|
||||
|
||||
/* password typing - form instructions */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_is_show_password', array(
|
||||
'default' => PPW_Constants::DEFAULT_IS_SHOW_PASSWORD,
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new PPW_Toggle_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_instructions_is_show_password_control', array(
|
||||
'label' => __( 'Show Password Reveal Button', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'type' => 'toggle',
|
||||
'settings' => 'ppwp_form_instructions_is_show_password',
|
||||
) )
|
||||
);
|
||||
|
||||
/* show password text */
|
||||
$wp_customize->add_setting( 'ppwp_form_instructions_show_password_text', array(
|
||||
'default' => PPW_Constants::DEFAULT_SHOW_PASSWORD_TEXT,
|
||||
) );
|
||||
|
||||
$wp_customize->add_control( 'ppwp_form_instructions_show_password_text_control', array(
|
||||
'label' => __( 'Button Text', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_instructions',
|
||||
'settings' => 'ppwp_form_instructions_show_password_text',
|
||||
'type' => 'text',
|
||||
) );
|
||||
|
||||
do_action('ppw_customize_after_form_instructions', $wp_customize);
|
||||
|
||||
/* form error message section */
|
||||
$wp_customize->add_section( 'ppwp_form_error_message', array(
|
||||
'title' => __( 'Error Messages', 'password-protect-page' ),
|
||||
'panel' => 'ppwp',
|
||||
'priority' => 200,
|
||||
) );
|
||||
|
||||
/* error message text */
|
||||
$wp_customize->add_setting( 'ppwp_form_error_message_text', array(
|
||||
'default' => __( apply_filters( PPW_Constants::HOOK_MESSAGE_ENTERING_WRONG_PASSWORD, PPW_Constants::DEFAULT_WRONG_PASSWORD_MESSAGE ), 'password-protect-page' ),
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new PPW_Text_Editor_Custom_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_error_message_text',
|
||||
array(
|
||||
'label' => __( 'Wrong Password Message', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_error_message',
|
||||
'settings' => 'ppwp_form_error_message_text',
|
||||
'type' => 'textarea',
|
||||
'priority' => 10,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
/* error message text */
|
||||
$wp_customize->add_setting( 'ppwp_form_error_recaptcha_message_text', array(
|
||||
'default' => __( PPW_Constants::DEFAULT_ERROR_RECAPTCHA_MESSAGE, 'password-protect-page' ),
|
||||
) );
|
||||
$wp_customize->add_control(
|
||||
new PPW_Text_Editor_Custom_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_error_recaptcha_message_text',
|
||||
array(
|
||||
'label' => __( 'Failed reCAPTCHA Message', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_error_message',
|
||||
'settings' => 'ppwp_form_error_recaptcha_message_text',
|
||||
'type' => 'textarea',
|
||||
'priority' => 15,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
/* error message font size */
|
||||
$wp_customize->add_setting( 'ppwp_form_error_message_text_font_size', array(
|
||||
'default' => PPW_Constants::DEFAULT_ERROR_TEXT_FONT_SIZE,
|
||||
) );
|
||||
|
||||
$wp_customize->add_control( 'ppwp_form_error_message_text_font_size_control', array(
|
||||
'label' => __( 'Font Size', 'password-protect-page' ),
|
||||
'description' => __( 'Font size in px', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_error_message',
|
||||
'settings' => 'ppwp_form_error_message_text_font_size',
|
||||
'type' => 'number',
|
||||
'priority' => 20,
|
||||
) );
|
||||
|
||||
/* error message font weight */
|
||||
$wp_customize->add_setting( 'ppwp_form_error_message_text_font_weight', array(
|
||||
'default' => PPW_Constants::DEFAULT_ERROR_TEXT_FONT_WEIGHT,
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_form_error_message_text_font_weight_control', array(
|
||||
'label' => __( 'Font Weight', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_error_message',
|
||||
'settings' => 'ppwp_form_error_message_text_font_weight',
|
||||
'type' => 'number',
|
||||
'priority' => 25,
|
||||
) );
|
||||
|
||||
/* error message text color */
|
||||
$wp_customize->add_setting( 'ppwp_form_error_message_text_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_ERROR_TEXT_FONT_COLOR,
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_error_message_text_color_control', array(
|
||||
'label' => __( 'Text Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_error_message',
|
||||
'settings' => 'ppwp_form_error_message_text_color',
|
||||
'priority' => 30,
|
||||
) )
|
||||
);
|
||||
|
||||
/* error message background color */
|
||||
$wp_customize->add_setting( 'ppwp_form_error_message_background_color', array(
|
||||
'default' => '#ffffff',
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_error_message_background_color_control', array(
|
||||
'label' => __( 'Background Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_error_message',
|
||||
'settings' => 'ppwp_form_error_message_background_color',
|
||||
'priority' => 35,
|
||||
) )
|
||||
);
|
||||
|
||||
/* form button */
|
||||
$wp_customize->add_section( 'ppwp_form_button', array(
|
||||
'title' => __( 'Button', 'password-protect-page' ),
|
||||
'panel' => 'ppwp',
|
||||
'priority' => 300,
|
||||
) );
|
||||
|
||||
/* button label */
|
||||
$wp_customize->add_setting( 'ppwp_form_button_label', array(
|
||||
'default' => __( PPW_Constants::DEFAULT_SUBMIT_LABEL, 'password-protect-page' ),
|
||||
) );
|
||||
$wp_customize->add_control( 'ppwp_form_button_label_control', array(
|
||||
'label' => __( 'Button Label', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_button',
|
||||
'settings' => 'ppwp_form_button_label',
|
||||
'type' => 'text',
|
||||
) );
|
||||
|
||||
/* button text color */
|
||||
$wp_customize->add_setting( 'ppwp_form_button_text_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_BUTTON_TEXT_FONT_COLOR,
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_button_text_color_control', array(
|
||||
'label' => __( 'Text Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_button',
|
||||
'settings' => 'ppwp_form_button_text_color',
|
||||
) )
|
||||
);
|
||||
|
||||
/* button text hover color */
|
||||
$wp_customize->add_setting( 'ppwp_form_button_text_hover_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_BUTTON_TEXT_HOVER_COLOR,
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_button_text_hover_color_control', array(
|
||||
'label' => __( 'Text Color (Hover)', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_button',
|
||||
'settings' => 'ppwp_form_button_text_hover_color',
|
||||
) )
|
||||
);
|
||||
|
||||
/* button background color */
|
||||
$wp_customize->add_setting( 'ppwp_form_button_background_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_BUTTON_BACKGROUND_COLOR,
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_button_background_color_control', array(
|
||||
'label' => __( 'Background Color', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_button',
|
||||
'settings' => 'ppwp_form_button_background_color',
|
||||
) )
|
||||
);
|
||||
|
||||
/* button background hover color */
|
||||
$wp_customize->add_setting( 'ppwp_form_button_background_hover_color', array(
|
||||
'default' => PPW_Constants::DEFAULT_BUTTON_BACKGROUND_HOVER_COLOR,
|
||||
) );
|
||||
|
||||
$wp_customize->add_control(
|
||||
new \WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
'ppwp_form_button_background_hover_color_control', array(
|
||||
'label' => __( 'Background Color (Hover)', 'password-protect-page' ),
|
||||
'section' => 'ppwp_form_button',
|
||||
'settings' => 'ppwp_form_button_background_hover_color',
|
||||
) )
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add dynamic styles
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dynamic_styles() {
|
||||
$below_text_styles = $this->get_below_text_style();
|
||||
$ppw_custom_css = "
|
||||
<style>
|
||||
.ppw-ppf-input-container {
|
||||
background-color: " . get_theme_mod( 'ppwp_form_instructions_background_color', PPW_Constants::DEFAULT_FORM_BACKGROUND_COLOR ) . "!important;
|
||||
padding: " . get_theme_mod( 'ppwp_form_instructions_padding', PPW_Constants::DEFAULT_FORM_PADDING ) . "px!important;
|
||||
border-radius: " . get_theme_mod( 'ppwp_form_instructions_border_radius', PPW_Constants::DEFAULT_FORM_BORDER_RADIUS ) . "px!important;
|
||||
}
|
||||
|
||||
.ppw-ppf-input-container div.ppw-ppf-headline {
|
||||
font-size: " . get_theme_mod( 'ppwp_form_instructions_headline_font_size', PPW_Constants::DEFAULT_HEADLINE_FONT_SIZE ) . "px!important;
|
||||
font-weight: " . get_theme_mod( 'ppwp_form_instructions_headline_font_weight', PPW_Constants::DEFAULT_HEADLINE_FONT_WEIGHT ) . "!important;
|
||||
color: " . get_theme_mod( 'ppwp_form_instructions_headline_color', PPW_Constants::DEFAULT_HEADLINE_FONT_COLOR ) . "!important;
|
||||
}
|
||||
|
||||
.ppw-ppf-input-container div.ppw-ppf-desc {
|
||||
font-size: " . get_theme_mod( 'ppwp_form_instructions_text_font_size', PPW_Constants::DEFAULT_TEXT_FONT_SIZE ) . "px!important;
|
||||
font-weight: " . get_theme_mod( 'ppwp_form_instructions_text_font_weight', PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT ) . "!important;
|
||||
color: " . get_theme_mod( 'ppwp_form_instructions_text_color', PPW_Constants::DEFAULT_TEXT_FONT_COLOR ) . "!important;
|
||||
}
|
||||
|
||||
.ppw-ppf-input-container label.ppw-pwd-label {
|
||||
font-size: " . get_theme_mod( 'ppwp_form_instructions_password_label_font_size', PPW_Constants::DEFAULT_TEXT_FONT_SIZE ) . "px!important;
|
||||
font-weight: " . get_theme_mod( 'ppwp_form_instructions_password_label_font_weight', PPW_Constants::DEFAULT_TEXT_FONT_WEIGHT ) . "!important;
|
||||
color: " . get_theme_mod( 'ppwp_form_instructions_password_label_color', PPW_Constants::DEFAULT_TEXT_FONT_COLOR ) . "!important;
|
||||
}
|
||||
|
||||
div.ppwp-wrong-pw-error {
|
||||
font-size: " . get_theme_mod( 'ppwp_form_error_message_text_font_size', PPW_Constants::DEFAULT_ERROR_TEXT_FONT_SIZE ) . "px!important;
|
||||
font-weight: " . get_theme_mod( 'ppwp_form_error_message_text_font_weight', PPW_Constants::DEFAULT_ERROR_TEXT_FONT_WEIGHT ) . "!important;
|
||||
color: " . get_theme_mod( 'ppwp_form_error_message_text_color', PPW_Constants::DEFAULT_ERROR_TEXT_FONT_COLOR ) . "!important;
|
||||
background: " . get_theme_mod( 'ppwp_form_error_message_background_color', PPW_Constants::DEFAULT_ERROR_TEXT_BACKGROUND_COLOR ) . "!important;
|
||||
}
|
||||
|
||||
.ppw-ppf-input-container input[type='submit'] {
|
||||
color: " . get_theme_mod( 'ppwp_form_button_text_color', PPW_Constants::DEFAULT_BUTTON_TEXT_FONT_COLOR ) . "!important;
|
||||
background: " . get_theme_mod( 'ppwp_form_button_background_color', PPW_Constants::DEFAULT_BUTTON_BACKGROUND_COLOR ) . "!important;
|
||||
}
|
||||
|
||||
.ppw-ppf-input-container input[type='submit']:hover {
|
||||
color: " . get_theme_mod( 'ppwp_form_button_text_hover_color', PPW_Constants::DEFAULT_BUTTON_TEXT_HOVER_COLOR ) . "!important;
|
||||
background: " . get_theme_mod( 'ppwp_form_button_background_hover_color', PPW_Constants::DEFAULT_BUTTON_BACKGROUND_HOVER_COLOR ) . "!important;
|
||||
}
|
||||
{$below_text_styles}
|
||||
</style>
|
||||
";
|
||||
|
||||
// compress $ppw_custom_css.
|
||||
$ppw_custom_css = preg_replace( "/\s{2,}/", " ", str_replace( "\n", "", str_replace( ', ', ",", $ppw_custom_css ) ) );
|
||||
|
||||
echo $ppw_custom_css;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue script for customizer control
|
||||
*/
|
||||
public function enqueue() {
|
||||
wp_enqueue_script( 'ppwp-customizer', PPW_DIR_URL . 'admin/js/customizer.js', array( 'jquery' ), PPW_VERSION, true );
|
||||
wp_localize_script(
|
||||
"ppwp-customizer",
|
||||
'ppw_data',
|
||||
array(
|
||||
'backgroundDIR' => PPW_DIR_URL . 'includes/customizers/assets/images/backgrounds/',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'PPW_Entire_Site_Services' ) ) {
|
||||
class PPW_Entire_Site_Services {
|
||||
/**
|
||||
* Auth cookie
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function validate_auth_cookie_entire_site() {
|
||||
$cookie_elements = $this->parse_cookie_entire_site();
|
||||
if ( false === $cookie_elements ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( (int) $cookie_elements[1] < time() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$password = ppw_core_get_setting_entire_site_type_string( PPW_Constants::PASSWORD_ENTIRE_SITE );
|
||||
$hash = hash_hmac( 'md5', PPW_Constants::ENTIRE_SITE_COOKIE_NAME, $password );
|
||||
|
||||
return $cookie_elements[0] === $hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse cookie
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
function parse_cookie_entire_site() {
|
||||
$_cookie = wp_unslash( $_COOKIE );
|
||||
$cookie_name = PPW_Constants::ENTIRE_SITE_COOKIE_NAME;
|
||||
if ( empty( $_cookie[ $cookie_name ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cookie = $_cookie[ $cookie_name ];
|
||||
$cookie_elements = explode( '|', $cookie );
|
||||
if ( count( $cookie_elements ) !== 2 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $cookie_elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check is valid password
|
||||
*
|
||||
* @param $password
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function entire_site_is_valid_password( $password ) {
|
||||
$_request = wp_unslash( $_REQUEST ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Processing form data without nonce verification. - Not verify nonce for password validate.
|
||||
if ( ! isset( $_request['input_wp_protect_password'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$password_input = $_request['input_wp_protect_password'];
|
||||
|
||||
$validated = md5( $password_input ) === $password;
|
||||
|
||||
return apply_filters( 'ppw_sitewide_valid_password', $validated );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set password to cookie
|
||||
*
|
||||
* @param string $password Password.
|
||||
*/
|
||||
public function entire_site_set_password_to_cookie( $password ) {
|
||||
$expiration = time() + 7 * DAY_IN_SECONDS;
|
||||
$cookie_expired = ppw_core_get_setting_type_string( PPW_Constants::COOKIE_EXPIRED );
|
||||
if ( ! empty( $cookie_expired ) ) {
|
||||
$time = explode( ' ', $cookie_expired )[0];
|
||||
$unit = ppw_core_get_unit_time( $cookie_expired );
|
||||
if ( 0 !== $unit ) {
|
||||
$expiration = time() + (int) $time * $unit;
|
||||
}
|
||||
}
|
||||
|
||||
$hash = hash_hmac( 'md5', PPW_Constants::ENTIRE_SITE_COOKIE_NAME, $password );
|
||||
$cookie = $hash . '|' . $expiration;
|
||||
$expiration = apply_filters( 'ppw_sitewide_cookie_expiration', $expiration, $password );
|
||||
ppw_free_bypass_cache_with_cookie_for_pro_version( $cookie, $expiration );
|
||||
setcookie( PPW_Constants::ENTIRE_SITE_COOKIE_NAME, $cookie, $expiration, COOKIEPATH, COOKIE_DOMAIN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect after enter password
|
||||
*/
|
||||
public function entire_site_redirect_after_enter_password() {
|
||||
// Can get the HTTP_REFERER first as the redirect URL that:
|
||||
// Fixes the private link redirection belonged to PPP Pro.
|
||||
$_server = wp_unslash( $_SERVER );
|
||||
if ( ! empty( $_server['HTTP_REFERER'] ) ) {
|
||||
$current_url = $_server['HTTP_REFERER'];
|
||||
} else {
|
||||
global $wp;
|
||||
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
|
||||
}
|
||||
|
||||
// TODO: consider to user wp_safe_redirect.
|
||||
wp_redirect( $current_url );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle before update settings for entire site
|
||||
*
|
||||
* @param $data_settings
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function handle_before_update_settings( $data_settings ) {
|
||||
// Clear cache Super Cache plugin
|
||||
// $free_cache = new PPW_Cache_Services();
|
||||
// $free_cache->clear_cache_super_cache();
|
||||
|
||||
if ( array_key_exists( PPW_Constants::IS_PROTECT_ENTIRE_SITE, $data_settings ) && $data_settings[ PPW_Constants::IS_PROTECT_ENTIRE_SITE ] === "true" ) {
|
||||
// Create new password
|
||||
if ( ! array_key_exists( PPW_Constants::SET_NEW_PASSWORD_ENTIRE_SITE, $data_settings ) ) {
|
||||
return $this->create_new_password( $data_settings );
|
||||
}
|
||||
|
||||
// Change password
|
||||
if ( array_key_exists( PPW_Constants::SET_NEW_PASSWORD_ENTIRE_SITE, $data_settings ) && $data_settings[ PPW_Constants::SET_NEW_PASSWORD_ENTIRE_SITE ] === "true" ) {
|
||||
return $this->change_password( $data_settings );
|
||||
}
|
||||
|
||||
// Don't change password
|
||||
return true;
|
||||
}
|
||||
|
||||
// Unprotect entire site
|
||||
return delete_option( PPW_Constants::ENTIRE_SITE_OPTIONS );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new password entire site
|
||||
*
|
||||
* @param $data_settings
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function create_new_password( $data_settings ) {
|
||||
$data_settings[ PPW_Constants::PASSWORD_ENTIRE_SITE ] = md5( $data_settings[ PPW_Constants::PASSWORD_ENTIRE_SITE ] );
|
||||
update_option( PPW_Constants::ENTIRE_SITE_OPTIONS, $data_settings );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change password entire site
|
||||
*
|
||||
* @param $data_settings
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function change_password( $data_settings ) {
|
||||
$data_settings[ PPW_Constants::PASSWORD_ENTIRE_SITE ] = md5( $data_settings[ PPW_Constants::PASSWORD_ENTIRE_SITE ] );
|
||||
unset( $data_settings[ PPW_Constants::SET_NEW_PASSWORD_ENTIRE_SITE ] );
|
||||
update_option( PPW_Constants::ENTIRE_SITE_OPTIONS, $data_settings );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: gaupoit
|
||||
* Date: 7/31/19
|
||||
* Time: 14:57
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'PPW_Default_PW_Manager_Services' ) ) {
|
||||
class PPW_Default_PW_Manager_Services extends PPW_Migration_Manager {
|
||||
/**
|
||||
* Get module name.
|
||||
*
|
||||
* Retrieve the module name.
|
||||
*
|
||||
* @return string Module name.
|
||||
* @since 1.7.0
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
public function get_name() {
|
||||
return 'default-pwd-migration';
|
||||
}
|
||||
|
||||
public function get_action() {
|
||||
return 'ppw_default_pwd_migration';
|
||||
}
|
||||
|
||||
public function get_plugin_name() {
|
||||
return 'ppw';
|
||||
}
|
||||
|
||||
public function get_plugin_label() {
|
||||
return __( PPW_PLUGIN_NAME, 'password-protect-page' );
|
||||
}
|
||||
|
||||
public function get_updater_label() {
|
||||
return sprintf( '<strong>%s </strong> –', __( 'Password Protect WordPress', 'password-protect-page' ) );
|
||||
}
|
||||
|
||||
public function get_query_limit() {
|
||||
// TODO: Implement get_query_limit() method.
|
||||
}
|
||||
|
||||
public function get_migrations_class() {
|
||||
return 'PPW_Default_PW_Migrations';
|
||||
}
|
||||
|
||||
public function get_migration_label() {
|
||||
return sprintf( '<strong>%s </strong> –', __( 'PPWP Data Migration', 'password-protect-page' ) );
|
||||
}
|
||||
|
||||
public function get_success_message() {
|
||||
return '<p>' . sprintf( __( '%s The <a href="https://passwordprotectwp.com/password-migration/" target="_blank" rel="noopener noreferrer">password migration process</a> is now complete. Thank you for your patience!', 'password-protect-page' ), $this->get_updater_label() ) . '</p>';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: gaupoit
|
||||
* Date: 7/25/19
|
||||
* Time: 14:48
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'PPW_Migration' ) ) {
|
||||
|
||||
class PPW_Migration extends PPW_Background_Task {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: gaupoit
|
||||
* Date: 7/31/19
|
||||
* Time: 14:57
|
||||
*/
|
||||
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'PPW_Default_PW_Migrations' ) ) {
|
||||
class PPW_Default_PW_Migrations {
|
||||
|
||||
public static function migrate_v_2_6_0() {
|
||||
error_log( 'Migrate Default Password' );
|
||||
$free_service = new PPW_Password_Services();
|
||||
$free_service->migrate_default_password();
|
||||
PPW_Options_Services::get_instance()->add_flag( PPW_Constants::MIGRATED_DEFAULT_PW );
|
||||
error_log( 'Migrated OK' );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: gaupoit
|
||||
* Date: 7/30/19
|
||||
* Time: 20:34
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'PPW_Options_Services' ) ) {
|
||||
|
||||
class PPW_Options_Services {
|
||||
|
||||
protected static $instance;
|
||||
|
||||
private $prefix;
|
||||
|
||||
public function __construct() {
|
||||
$this->prefix = 'ppw_pro';
|
||||
}
|
||||
|
||||
public static function get_instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new PPW_Options_Services();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function add_flag( $flag ) {
|
||||
update_option( $this->prefix . '_' . $flag, 1 );
|
||||
}
|
||||
|
||||
public function get_flag( $flag ) {
|
||||
return get_option( $this->prefix . '_' . $flag );
|
||||
}
|
||||
|
||||
public function delete_flag( $flag ) {
|
||||
$option_name = $this->prefix . '_' . $flag;
|
||||
if ( is_multisite() ) {
|
||||
foreach ( get_sites() as $site ) {
|
||||
delete_blog_option( $site->blog_id, $option_name );
|
||||
}
|
||||
} else {
|
||||
delete_option( $option_name );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
class PPW_Password_Recovery_Manager extends PPW_Background_Task_Manager {
|
||||
private $completed;
|
||||
|
||||
public function __construct() {
|
||||
$this->handle_admin_notices();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function handle_admin_notices() {
|
||||
if ( ! is_admin() ) {
|
||||
return;
|
||||
}
|
||||
$action = 'admin_notices';
|
||||
|
||||
if ( $this->is_completed() ) {
|
||||
add_action( $action, array( $this, 'admin_notice_upgrade_is_completed' ) );
|
||||
}
|
||||
|
||||
if ( $this->is_running() ) {
|
||||
add_action( $action, array( $this, 'admin_notice_upgrade_is_running' ) );
|
||||
}
|
||||
}
|
||||
|
||||
public function is_running() {
|
||||
$task_runner = $this->get_task_runner();
|
||||
|
||||
return $task_runner->is_running();
|
||||
}
|
||||
|
||||
public function is_completed() {
|
||||
if ( isset( $this->completed ) ) {
|
||||
return $this->completed;
|
||||
}
|
||||
$this->completed = $this->get_flag( 'completed' );
|
||||
|
||||
return $this->completed;
|
||||
}
|
||||
|
||||
public function get_task_runner_class() {
|
||||
return 'PPW_Password_Recovery';
|
||||
}
|
||||
|
||||
public function get_query_limit() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
public function on_runner_complete( $did_tasks = false ) {
|
||||
// Implement log here
|
||||
if ( $did_tasks ) {
|
||||
$this->add_flag( 'completed' );
|
||||
}
|
||||
}
|
||||
|
||||
public function start_run() {
|
||||
$updater = $this->get_task_runner();
|
||||
|
||||
if ( $updater->is_running() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$restore_password_callbacks = $this->get_restore_password_callbacks();
|
||||
|
||||
if ( empty( $restore_password_callbacks ) ) {
|
||||
$this->on_runner_complete();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $restore_password_callbacks as $callback ) {
|
||||
$updater->push_to_queue(
|
||||
array(
|
||||
'callback' => $callback,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$updater->save()->dispatch();
|
||||
}
|
||||
|
||||
public function get_restore_password_callbacks() {
|
||||
$callbacks[] = array( 'PPW_Password_Recovery_Manager', 'restore_passwords' );
|
||||
|
||||
return $callbacks;
|
||||
}
|
||||
|
||||
public static function restore_passwords() {
|
||||
return ( new PPW_Password_Services() )->restore_wp_post_password();
|
||||
}
|
||||
|
||||
public function admin_notice_upgrade_is_running() {
|
||||
$continue_action = $this->get_continue_action_url();
|
||||
$message = '<p>'
|
||||
. __( 'Password recovery process is running in the background.', 'password-protect-page' )
|
||||
. '</p>'
|
||||
. '<p>'
|
||||
. sprintf( 'Taking a while? <a href="%s" class="button-primary">Click here to run it now</a>', $continue_action )
|
||||
. '</p>';
|
||||
echo '<div class="notice notice-warning">' . wp_kses_post( $message ) . '</div>';
|
||||
}
|
||||
|
||||
public function admin_notice_upgrade_is_completed() {
|
||||
$this->delete_flag( 'completed' );
|
||||
$message = $this->get_success_message();
|
||||
if ( ! empty( $message ) ) {
|
||||
echo '<div class="notice notice-success">' . wp_kses_post( $message ) . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
public function get_action() {
|
||||
return 'password_recovery_process';
|
||||
}
|
||||
|
||||
public function get_plugin_name() {
|
||||
return 'ppw';
|
||||
}
|
||||
|
||||
public function get_plugin_label() {
|
||||
return __( PPW_PLUGIN_NAME, 'password-protect-page' );
|
||||
}
|
||||
|
||||
public function get_name() {
|
||||
return 'ppw-password-recovery';
|
||||
}
|
||||
|
||||
public function get_success_message() {
|
||||
return '<p>' . sprintf( __( '%s <a href="https://passwordprotectwp.com/docs/password-migration/#backup" target="_blank" rel="noopener noreferrer">Password recovery process</a> is now complete.. Thank you for your patience!', 'password-protect-page' ), $this->get_updater_label() ) . '</p>';
|
||||
}
|
||||
|
||||
public function get_updater_label() {
|
||||
return sprintf( '<strong>%s </strong> –', __( 'Password Protect WordPress', 'password-protect-page' ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: gaupoit
|
||||
* Date: 7/25/19
|
||||
* Time: 14:48
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class PPW_Password_Recovery extends PPW_Background_Task {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,566 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Class PPW_Recaptcha
|
||||
*/
|
||||
class PPW_Recaptcha {
|
||||
const TYPE_PARAM = 'ppwp_type';
|
||||
const TYPE_VALUE = 'recaptcha';
|
||||
|
||||
const RECAPTCHA_V3_TYPE = 'recaptcha_v3';
|
||||
const RECAPTCHA_V2_CHECKBOX_TYPE = 'recaptcha_v2_checkbox';
|
||||
const RECAPTCHA_V2_INVISIBLE_TYPE = 'recaptcha_v2_invisible';
|
||||
const SINGLE_PASSWORD = 'single';
|
||||
const PCP_PASSWORD = 'pcp';
|
||||
const SITEWIDE_PASSWORD = 'sitewide';
|
||||
|
||||
private $show_message = false;
|
||||
|
||||
/**
|
||||
* @var PPW_Recaptcha
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* @return PPW_Recaptcha
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recaptcha error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_error_message() {
|
||||
$message = get_theme_mod( 'ppwp_form_error_recaptcha_message_text', PPW_Constants::DEFAULT_ERROR_RECAPTCHA_MESSAGE );
|
||||
$message = wp_kses_post( $message );
|
||||
|
||||
return _x( $message, PPW_Constants::CONTEXT_PASSWORD_FORM, 'password-protect-page' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register hooks.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function register() {
|
||||
add_filter( 'ppwp_customize_ppf', array( $this, 'maybe_customize_error_message' ), 25 );
|
||||
add_filter( 'ppwp_ppf_redirect_url', array( $this, 'maybe_add_blocked_message' ), 20, 2 );
|
||||
add_filter( 'ppwp_ppf_referrer_url', array( $this, 'maybe_remove_recaptcha_query' ), 10, 2 );
|
||||
add_filter( 'ppwpea_recaptcha_v2_site_key', array( $this, 'get_ppwpea_recaptcha_v2_api_key' ), 10 );
|
||||
add_filter( 'ppwpea_recaptcha_v2_secret', array( $this, 'get_ppwpea_recaptcha_v2_api_secret' ), 10 );
|
||||
add_action( 'wp_footer', array( $this, 'load_js_in_footer' ), 10 );
|
||||
add_action( 'ppw_custom_footer_form_entire_site', array( $this, 'maybe_load_sitewide_recaptcha_js' ), 10 );
|
||||
add_action( 'ppw_sitewide_above_submit_button', array( $this, 'maybe_add_recaptcha_input_below_sitewide_form' ), 10 );
|
||||
add_action( 'ppw_sitewide_custom_internal_css', array( $this, 'customize_sitewide_css' ), 10 );
|
||||
add_filter( 'ppw_sitewide_valid_password', array( $this, 'validate_sitewide_password' ), 10 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove blocked query if user enter right password.
|
||||
*
|
||||
* @param string $referrer_url Referrer URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function maybe_remove_recaptcha_query( $referrer_url ) {
|
||||
if ( ! $this->using_single_recaptcha() ) {
|
||||
return $referrer_url;
|
||||
}
|
||||
|
||||
if ( $this->has_recaptcha_parameter( $referrer_url ) ) {
|
||||
$referrer_url = add_query_arg( self::TYPE_PARAM, false, $referrer_url );
|
||||
}
|
||||
|
||||
return $referrer_url;
|
||||
}
|
||||
|
||||
public function using_recaptcha() {
|
||||
return ppw_core_get_setting_type_bool_by_option_name( PPW_Constants::USING_RECAPTCHA, PPW_Constants::EXTERNAL_OPTIONS );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add blocked message if user turn on option.
|
||||
*
|
||||
* @param string $redirect_url Redirect URL.
|
||||
* @param array $params Parameters.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function maybe_add_blocked_message( $redirect_url, $params ) {
|
||||
if ( ! $this->using_single_recaptcha() ) {
|
||||
return $redirect_url;
|
||||
}
|
||||
if ( $params['is_valid'] ) {
|
||||
return $redirect_url;
|
||||
}
|
||||
|
||||
if ( ! $this->show_message ) {
|
||||
// Remove blocked parameter if URL has it.
|
||||
if ( $this->has_recaptcha_parameter( $redirect_url ) ) {
|
||||
$redirect_url = add_query_arg( self::TYPE_PARAM, false, $redirect_url );
|
||||
}
|
||||
|
||||
return $redirect_url;
|
||||
}
|
||||
|
||||
$redirect_url = add_query_arg( self::TYPE_PARAM, self::TYPE_VALUE, $redirect_url );
|
||||
|
||||
return $redirect_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has recaptcha parameter on URL.
|
||||
*
|
||||
* @param string $url $url URL.
|
||||
* @param string $query_value Query value.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function has_recaptcha_parameter( $url = '', $query_value = self::TYPE_VALUE ) {
|
||||
if ( empty( $url ) ) {
|
||||
$query_params = ppw_core_get_query_param();
|
||||
} else {
|
||||
$query_params = ppw_core_get_param_in_url( $url );
|
||||
}
|
||||
|
||||
if ( ! isset( $query_params[ self::TYPE_PARAM ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $query_value === $query_params[ self::TYPE_PARAM ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Customize error message.
|
||||
*
|
||||
* @param array $params Parameters.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function maybe_customize_error_message( $params ) {
|
||||
if ( ! $this->using_single_recaptcha() ) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
if ( $this->has_recaptcha_parameter() ) {
|
||||
$message = $this->get_error_message();
|
||||
$params['error_msg'] = apply_filters( 'ppw_recaptcha_error_message', $message, $params );
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate recaptcha.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_valid_recaptcha() {
|
||||
$_post = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- We no need to handle nonce verification here because already handle on parent function.
|
||||
if ( ! isset( $_post['g-recaptcha-response'] ) ) {
|
||||
$this->show_message = true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = $this->verify_recaptcha( $_post['g-recaptcha-response'] );
|
||||
if ( ! $result['success'] ) {
|
||||
$this->show_message = true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get limit score.
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function get_limit_score() {
|
||||
$score = ppw_core_get_settings_by_option_name( PPW_Constants::RECAPTCHA_SCORE, PPW_Constants::EXTERNAL_OPTIONS );
|
||||
if ( is_null( $score ) ) {
|
||||
return (double) 0.5;
|
||||
}
|
||||
|
||||
return (double) $score;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting api key of recaptcha with current type.
|
||||
*
|
||||
* @param string $type Recaptcha type.
|
||||
* @param string $default Default value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_setting_api_key( $type = '', $default = '' ) {
|
||||
if ( empty( $type ) ) {
|
||||
$type = $this->get_recaptcha_type();
|
||||
}
|
||||
|
||||
switch ( $type ) {
|
||||
case self::RECAPTCHA_V3_TYPE:
|
||||
return $this->get_recaptcha_v3_api_key();
|
||||
case self::RECAPTCHA_V2_CHECKBOX_TYPE:
|
||||
return $this->get_recaptcha_v2_api_key();
|
||||
default:
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting api secret of recaptcha with current type.
|
||||
*
|
||||
* @param string $type Recaptcha type.
|
||||
* @param string $default Default value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_setting_api_secret( $type = '', $default = '' ) {
|
||||
if ( empty( $type ) ) {
|
||||
$type = $this->get_recaptcha_type();
|
||||
}
|
||||
|
||||
switch ( $type ) {
|
||||
case self::RECAPTCHA_V3_TYPE:
|
||||
return $this->get_recaptcha_v3_api_secret();
|
||||
case self::RECAPTCHA_V2_CHECKBOX_TYPE:
|
||||
return $this->get_recaptcha_v2_api_secret();
|
||||
default:
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recaptcha v3 API key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_recaptcha_v3_api_key() {
|
||||
return ppw_core_get_setting_type_string_by_option_name( PPW_Constants::RECAPTCHA_API_KEY, PPW_Constants::EXTERNAL_OPTIONS );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recaptcha v3 API secret.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_recaptcha_v3_api_secret() {
|
||||
return ppw_core_get_setting_type_string_by_option_name( PPW_Constants::RECAPTCHA_API_SECRET, PPW_Constants::EXTERNAL_OPTIONS );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recaptcha v2 API key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_recaptcha_v2_api_key() {
|
||||
return ppw_core_get_setting_type_string_by_option_name( PPW_Constants::RECAPTCHA_V2_CHECKBOX_API_KEY, PPW_Constants::EXTERNAL_OPTIONS );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recaptcha v2 API secret.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_recaptcha_v2_api_secret() {
|
||||
return ppw_core_get_setting_type_string_by_option_name( PPW_Constants::RECAPTCHA_V2_CHECKBOX_API_SECRET, PPW_Constants::EXTERNAL_OPTIONS );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recaptcha type.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_recaptcha_type() {
|
||||
$recaptcha_type = ppw_core_get_setting_type_string_by_option_name( PPW_Constants::RECAPTCHA_TYPE, PPW_Constants::EXTERNAL_OPTIONS );
|
||||
|
||||
return $recaptcha_type ? $recaptcha_type : self::RECAPTCHA_V3_TYPE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get password types selected.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_password_types() {
|
||||
$password_types = ppw_core_get_setting_type_array_by_option_name( PPW_Constants::RECAPTCHA_PASSWORD_TYPES, PPW_Constants::EXTERNAL_OPTIONS );
|
||||
|
||||
return $password_types ? $password_types : array( 'single' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Using single recaptcha
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function using_single_recaptcha() {
|
||||
return $this->using_recaptcha() && in_array( self::SINGLE_PASSWORD, $this->get_password_types() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Using sitewide recaptcha
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function using_sitewide_recaptcha() {
|
||||
return $this->using_recaptcha() && in_array( self::SITEWIDE_PASSWORD, $this->get_password_types() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Using sitewide recaptcha
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function using_pcp_recaptcha() {
|
||||
return $this->using_recaptcha() && in_array( self::PCP_PASSWORD, $this->get_password_types() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load recaptcha v2 javascript.
|
||||
*/
|
||||
public function load_recaptcha_v2_js() {
|
||||
ob_start();
|
||||
?>
|
||||
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
|
||||
<?php
|
||||
|
||||
echo ob_get_clean(); // phpcs:ignore -- we cannot escape ob_start ob_get_clean(), there are no variable to escape in statement above
|
||||
}
|
||||
|
||||
/**
|
||||
* Load recaptcha v3 javascript.
|
||||
*/
|
||||
public function load_recaptcha_v3_js() {
|
||||
$recaptcha_key = $this->get_recaptcha_v3_api_key();
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<script src="https://www.google.com/recaptcha/api.js?render=<?php echo esc_attr( $recaptcha_key ); ?>"></script>
|
||||
<script>
|
||||
grecaptcha.ready(function () {
|
||||
grecaptcha.execute('<?php echo esc_attr( $recaptcha_key ); ?>', {action: 'enter_password'}).then(function (token) {
|
||||
var recaptchaResponse = document.getElementById('ppwRecaptchaResponse');
|
||||
recaptchaResponse.value = token;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
|
||||
echo ob_get_clean(); // phpcs:ignore -- we already escape the $recaptcha_key above
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify google recaptcha V3.
|
||||
*
|
||||
* @param string $recaptcha_response Recaptcha response.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function verify_recaptcha( $recaptcha_response ) {
|
||||
$default = array(
|
||||
'success' => false,
|
||||
'message' => '',
|
||||
);
|
||||
if ( ! $recaptcha_response ) {
|
||||
return $default;
|
||||
}
|
||||
$secret = $this->get_setting_api_secret();
|
||||
if ( ! $secret ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$response = wp_remote_post(
|
||||
'https://www.google.com/recaptcha/api/siteverify',
|
||||
array(
|
||||
'method' => 'POST',
|
||||
'timeout' => 45,
|
||||
'redirection' => 5,
|
||||
'httpversion' => '1.0',
|
||||
'blocking' => true,
|
||||
'headers' => array(),
|
||||
'body' => array(
|
||||
'secret' => $secret,
|
||||
'response' => $recaptcha_response,
|
||||
),
|
||||
'cookies' => array(),
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
$body = json_decode( $body );
|
||||
|
||||
// Whether this request was a valid reCAPTCHA token for your site.
|
||||
$success = isset( $body->success ) && $body->success;
|
||||
|
||||
$external = true;
|
||||
if ( $this->get_recaptcha_type() === self::RECAPTCHA_V3_TYPE ) {
|
||||
$limit_score = $this->get_limit_score();
|
||||
|
||||
// The score for this request (0.0 - 1.0) 1.0 is very likely a good interaction, 0.0 is very likely a bot.
|
||||
$score = isset( $body->score ) ? (double) $body->score : 0;
|
||||
$external = $score > $limit_score;
|
||||
}
|
||||
$default['success'] = $success && $external;
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load PPWPEA api key.
|
||||
*
|
||||
* @param string $key Recaptcha API key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_ppwpea_recaptcha_v2_api_key( $key ) {
|
||||
return $this->get_recaptcha_v2_api_key();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load PPWPEA api secret.
|
||||
*
|
||||
* @param string $secret Recaptcha API secret.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_ppwpea_recaptcha_v2_api_secret( $secret ) {
|
||||
return $this->get_recaptcha_v2_api_secret();
|
||||
}
|
||||
|
||||
public function maybe_load_sitewide_recaptcha_js() {
|
||||
if ( ! $this->using_sitewide_recaptcha() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->add_recaptcha_to_head();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add recaptcha to head.
|
||||
*/
|
||||
public function add_recaptcha_to_head() {
|
||||
$recaptcha_type = $this->get_recaptcha_type();
|
||||
switch ( $recaptcha_type ) {
|
||||
case self::RECAPTCHA_V3_TYPE:
|
||||
$this->load_recaptcha_v3_js();
|
||||
break;
|
||||
case self::RECAPTCHA_V2_CHECKBOX_TYPE:
|
||||
case self::RECAPTCHA_V2_INVISIBLE_TYPE:
|
||||
$this->load_recaptcha_v2_js();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add recaptcha input below sitewide form.
|
||||
*/
|
||||
public function maybe_add_recaptcha_input_below_sitewide_form() {
|
||||
$recaptcha_input = $this->get_recaptcha_input();
|
||||
if ( ! empty( $recaptcha_input ) ) {
|
||||
echo $recaptcha_input;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recaptcha input.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_recaptcha_input() {
|
||||
switch ( $this->get_recaptcha_type() ) {
|
||||
case PPW_Recaptcha::RECAPTCHA_V2_CHECKBOX_TYPE:
|
||||
$site_key = $this->get_recaptcha_v2_api_key();
|
||||
|
||||
return '<div class="ppw-recaptcha g-recaptcha" data-sitekey="' . $site_key . '"></div>';
|
||||
default:
|
||||
return '<input type="hidden" name="g-recaptcha-response" id="ppwRecaptchaResponse" />';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Customize sitewide css.
|
||||
*/
|
||||
public function customize_sitewide_css() {
|
||||
if ( ! $this->using_sitewide_recaptcha() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
||||
.g-recaptcha {
|
||||
transform:scale(0.9);
|
||||
transform-origin:0 0;
|
||||
}
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate sitewide password form.
|
||||
*
|
||||
* @param $validated
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validate_sitewide_password( $validated ) {
|
||||
if ( ! $validated ) {
|
||||
return $validated;
|
||||
}
|
||||
|
||||
if ( ! $this->using_sitewide_recaptcha() ) {
|
||||
return $validated;
|
||||
}
|
||||
|
||||
if ( ! $this->is_valid_recaptcha() ) {
|
||||
add_filter( 'ppw_sitewide_error_message', array( $this, 'get_sitewide_error_message' ) );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $validated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sitewide error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_sitewide_error_message() {
|
||||
return __( 'Google reCAPTCHA verification failed, please try again later.', 'password-protect-page' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load JS in footer.
|
||||
*/
|
||||
public function load_js_in_footer() {
|
||||
if ( ! $this->using_single_recaptcha() ) {
|
||||
return;
|
||||
}
|
||||
$allowed = is_singular();
|
||||
$allowed = apply_filters( 'ppw_recaptcha_allowed_to_load_script', $allowed );
|
||||
if ( ! $allowed ) {
|
||||
return;
|
||||
}
|
||||
$post_id = get_the_ID();
|
||||
if ( ! $post_id || ! post_password_required( $post_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->add_recaptcha_to_head();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,803 @@
|
||||
<?php
|
||||
/**
|
||||
* PPWP Shortcoe
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'PPW_Shortcode' ) ) {
|
||||
/**
|
||||
*
|
||||
* Class PPW_Shortcode
|
||||
*/
|
||||
class PPW_Shortcode {
|
||||
|
||||
/**
|
||||
* Short code attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $attributes;
|
||||
|
||||
/**
|
||||
* Supported roles.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $supported_roles;
|
||||
|
||||
/**
|
||||
* Supported post types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $supported_post_types;
|
||||
|
||||
/**
|
||||
* The main class name which using to add the index.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $main_class_name;
|
||||
|
||||
/**
|
||||
* Register the short code ppwp_content_protector with WordPress
|
||||
* and include the asserts for it.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->attributes = apply_filters(
|
||||
PPW_Constants::HOOK_SHORT_CODE_ATTRS,
|
||||
array(
|
||||
'passwords' => '',
|
||||
'headline' => PPW_Constants::DEFAULT_SHORTCODE_HEADLINE,
|
||||
'description' => PPW_Constants::DEFAULT_SHORTCODE_DESCRIPTION,
|
||||
'id' => '',
|
||||
'class' => '',
|
||||
'placeholder' => '',
|
||||
'button' => PPW_Constants::DEFAULT_SHORTCODE_BUTTON,
|
||||
'whitelisted_roles' => '',
|
||||
'group' => '',
|
||||
'label' => PPW_Constants::DEFAULT_SHORTCODE_LABEL,
|
||||
'error_msg' => PPW_Constants::DEFAULT_SHORTCODE_ERROR_MSG,
|
||||
'loading' => PPW_Constants::DEFAULT_SHORTCODE_LOADING,
|
||||
'on' => '',
|
||||
'off' => '',
|
||||
'acf_field' => '',
|
||||
'show_password' => PPW_Constants::DEFAULT_SHORTCODE_SHOW_PASSWORD,
|
||||
'show_password_text' => PPW_Constants::DEFAULT_SHORTCODE_SHOW_PASSWORD_TEXT,
|
||||
'section' => 0,
|
||||
'desc_above_btn' => PPW_Constants::DEFAULT_SHORTCODE_DESC_ABOVE_PWD_BTN,
|
||||
'desc_below_form' => PPW_Constants::DEFAULT_SHORTCODE_DESC_BELOW_PWD_FORM,
|
||||
)
|
||||
);
|
||||
|
||||
// Defined by WordPress: https://wordpress.org/support/article/roles-and-capabilities/.
|
||||
$this->supported_roles = apply_filters(
|
||||
PPW_Constants::HOOK_SUPPORTED_WHITELIST_ROLES,
|
||||
array(
|
||||
'administrator',
|
||||
'editor',
|
||||
'author',
|
||||
'contributor',
|
||||
'subscriber',
|
||||
)
|
||||
);
|
||||
|
||||
$this->supported_post_types = apply_filters(
|
||||
PPW_Constants::HOOK_SUPPORTED_POST_TYPES,
|
||||
array(
|
||||
'page',
|
||||
'post',
|
||||
)
|
||||
);
|
||||
|
||||
add_shortcode( PPW_Constants::PPW_HOOK_SHORT_CODE_NAME, array( $this, 'render_shortcode' ) );
|
||||
add_filter( 'ppw_content_shortcode_source', array( $this, 'render_block_content' ), 15 );
|
||||
|
||||
// Support page builder.
|
||||
add_action( 'the_post', array( $this, 'maybe_remove_ppwp_shortcode' ), 10 );
|
||||
add_action( 'the_post', array( $this, 'maybe_add_ppwp_shortcode' ), 99999 );
|
||||
|
||||
|
||||
/**
|
||||
* Need to keep the old Pro version work, because the sidewide shortcode is using global var ppwContentGlobal.
|
||||
*/
|
||||
if ( defined( 'PPW_PRO_VERSION' ) ) {
|
||||
$pro_version = ppw_get_pro_version();
|
||||
if ( version_compare( $pro_version, '1.2.2', '<' ) ) {
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts' ) );
|
||||
}
|
||||
}
|
||||
|
||||
$this->main_class_name = PPW_Constants::DEFAULT_SHORTCODE_CLASS_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe remove shortcode before WPBakery and WordPress do_shortcode in FrontEnd.
|
||||
*/
|
||||
public function maybe_remove_ppwp_shortcode() {
|
||||
if ( ! ppw_free_has_support_shortcode_page_builder() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
remove_shortcode( PPW_Constants::PPW_HOOK_SHORT_CODE_NAME );
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe add shortcode back.
|
||||
*/
|
||||
public function maybe_add_ppwp_shortcode() {
|
||||
if ( ! ppw_free_has_support_shortcode_page_builder() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_filter( 'the_content', function ( $content ) {
|
||||
add_shortcode( PPW_Constants::PPW_HOOK_SHORT_CODE_NAME, array( $this, 'render_shortcode' ) );
|
||||
|
||||
/* translators: Opening curly double quote. */
|
||||
$opening_quote = _x( '“', 'opening curly double quote' );
|
||||
/* translators: Closing curly double quote. */
|
||||
$closing_quote = _x( '”', 'closing curly double quote' );
|
||||
/* translators: Apostrophe, for example in 'cause or can't. */
|
||||
$apos = _x( '’', 'apostrophe' );
|
||||
/* translators: Prime, for example in 9' (nine feet). */
|
||||
$prime = _x( '′', 'prime' );
|
||||
/* translators: Double prime, for example in 9" (nine inches). */
|
||||
$double_prime = _x( '″', 'double prime' );
|
||||
/* translators: Opening curly single quote. */
|
||||
$opening_single_quote = _x( '‘', 'opening curly single quote' );
|
||||
/* translators: Closing curly single quote. */
|
||||
$closing_single_quote = _x( '’', 'closing curly single quote' );
|
||||
|
||||
$matches = ppw_free_search_shortcode_content( $content );
|
||||
if ( ! empty( $matches ) ) {
|
||||
foreach ( $matches as $match ) {
|
||||
// The shortcode argument list
|
||||
$old_argument_shortcode = $match[3];
|
||||
$argument_shortcode = $match[3];
|
||||
|
||||
$argument_shortcode = str_replace( $opening_quote, '"', $argument_shortcode );
|
||||
$argument_shortcode = str_replace( $closing_quote, '"', $argument_shortcode );
|
||||
$argument_shortcode = str_replace( $apos, '\'', $argument_shortcode );
|
||||
$argument_shortcode = str_replace( $prime, '\'', $argument_shortcode );
|
||||
$argument_shortcode = str_replace( $double_prime, '"', $argument_shortcode );
|
||||
$argument_shortcode = str_replace( $opening_single_quote, '\'', $argument_shortcode );
|
||||
$argument_shortcode = str_replace( $closing_single_quote, '\'', $argument_shortcode );
|
||||
|
||||
$content = str_replace( $old_argument_shortcode, $argument_shortcode, $content );
|
||||
}
|
||||
}
|
||||
|
||||
$content = do_shortcode( $content );
|
||||
|
||||
return $content;
|
||||
}, 99999 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short code instance
|
||||
*
|
||||
* @return PPW_Shortcode
|
||||
*/
|
||||
public static function get_instance() {
|
||||
return new PPW_Shortcode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render password form or restricted content
|
||||
* 0. Check current post type is in whitelist types
|
||||
* 1. Check is valid attributes
|
||||
* 2. Check whitelist roles
|
||||
* 3. Check password is correct compare to Cookie
|
||||
* 4. Show form
|
||||
*
|
||||
* @param array $attrs list of attributes including password.
|
||||
* @param string $content the content inside short code.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render_shortcode( $attrs, $content = null ) {
|
||||
global $page;
|
||||
|
||||
// In case the shortcode is outside in the loop, the page is 0.
|
||||
$number = ! empty( $page ) ? $page : 1;
|
||||
|
||||
$this->attributes = apply_filters( 'ppw_pcp_attributes', $this->attributes, $number );
|
||||
$attrs = shortcode_atts(
|
||||
$this->attributes,
|
||||
$attrs
|
||||
);
|
||||
|
||||
$message = $this->is_valid_shortcode( $attrs, $content );
|
||||
$message = apply_filters( 'ppw_pcp_valid_shortcode', $message, $attrs );
|
||||
if ( true !== $message ) {
|
||||
return $this->get_invalid_shortcode_message( $message, $attrs );
|
||||
}
|
||||
|
||||
$content = sprintf(
|
||||
'<div class="%s">%s</div>',
|
||||
$this->get_main_class_name( $attrs ),
|
||||
do_shortcode( $content )
|
||||
);
|
||||
|
||||
$whitelisted_roles = apply_filters( PPW_Constants::HOOK_SHORT_CODE_WHITELISTED_ROLES, $attrs['whitelisted_roles'] );
|
||||
|
||||
if ( $this->is_whitelisted_role( $whitelisted_roles ) ) {
|
||||
// Remember to wrap the content between the parent div. If you want to replace the shortcode content.
|
||||
return apply_filters( PPW_Constants::HOOK_SHORTCODE_RENDER_CONTENT, $content, $attrs );
|
||||
}
|
||||
|
||||
// Unlock content by datetime.
|
||||
$unlocked = apply_filters( 'ppw_shortcode_unlock_content', $this->is_unlock_content_by_time( $attrs ), $attrs );
|
||||
if ( $unlocked ) {
|
||||
return apply_filters( PPW_Constants::HOOK_SHORTCODE_RENDER_CONTENT, $content, $attrs );
|
||||
}
|
||||
|
||||
do_action( PPW_Constants::HOOK_SHORT_CODE_BEFORE_CHECK_PASSWORD, $content );
|
||||
|
||||
// Passwords attribute format: passwords="123 345 898942".
|
||||
$passwords = apply_filters( PPW_Constants::HOOK_SHORTCODE_PASSWORDS, array_filter( explode( ' ', trim( $attrs['passwords'] ) ), 'strlen' ), $attrs );
|
||||
|
||||
foreach ( $passwords as $password ) {
|
||||
// When passwords attribute having special characters eg: <script>alert('hello')</script>. WP will encode the HTML tag. Need to decode to compare the value in Cookie.
|
||||
$hashed_password = wp_hash_password( wp_specialchars_decode( $password ) );
|
||||
if ( $this->is_valid_password( $hashed_password ) ) {
|
||||
// Remember to wrap the content between the parent div. If you want to replace the shortcode content.
|
||||
return apply_filters( PPW_Constants::HOOK_SHORTCODE_RENDER_CONTENT, $content, $attrs );
|
||||
}
|
||||
}
|
||||
|
||||
do_action( PPW_Constants::HOOK_SHORT_CODE_AFTER_CHECK_PASSWORD, $content );
|
||||
|
||||
$this->add_scripts();
|
||||
|
||||
// Show custom text instead of password form.
|
||||
$custom_form = apply_filters( PPW_Constants::HOOK_SHORTCODE_BEFORE_RENDER_PASSWORD_FORM, false, $attrs );
|
||||
if ( false !== $custom_form ) {
|
||||
return sprintf(
|
||||
'<div class="%s">%s</div>',
|
||||
$this->get_main_class_name( $attrs ),
|
||||
$this->massage_attributes( $custom_form )
|
||||
);
|
||||
}
|
||||
|
||||
$password_form = $this->get_restricted_content_form( $attrs, $number );
|
||||
|
||||
return apply_filters( 'ppw_pcp_password_form', $password_form, $attrs );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show content if user set on_date or off_date attribute.
|
||||
* $on_date: Date to unlock content
|
||||
* $off_date: Date to protect content.
|
||||
*
|
||||
* @param array $attrs Attributes.
|
||||
*
|
||||
* @return false True is unlock content else false.
|
||||
*/
|
||||
private function is_unlock_content_by_time( $attrs ) {
|
||||
$on_date = false;
|
||||
if ( '' !== $attrs['on'] ) {
|
||||
$on_date = strtotime( $attrs['on'] );
|
||||
}
|
||||
|
||||
$off_date = false;
|
||||
if ( '' !== $attrs['off'] ) {
|
||||
$off_date = strtotime( $attrs['off'] );
|
||||
}
|
||||
|
||||
// Show password form if on_date and off_date are empty.
|
||||
if ( ! $on_date && ! $off_date ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$now = current_time( 'timestamp' );
|
||||
|
||||
// Unlock content between on_date and off_date.
|
||||
if ( $on_date && $off_date && $on_date <= $now && $off_date >= $now ) {
|
||||
return apply_filters( 'ppw_shortcode_unlock_content_by_time', true, $attrs );
|
||||
}
|
||||
|
||||
// Unlock content from on_date.
|
||||
if ( $on_date && ! $off_date && $now >= $on_date ) {
|
||||
return apply_filters( 'ppw_shortcode_unlock_content_by_time', true, $attrs );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Require javascript bundle file for shortcode.
|
||||
*/
|
||||
public function add_scripts() {
|
||||
static $count_script = 0;
|
||||
$count_script ++;
|
||||
|
||||
$assert_folder = '/public/js/dist';
|
||||
$is_using_pcp_recaptcha = PPW_Recaptcha::get_instance()->using_pcp_recaptcha();
|
||||
|
||||
wp_enqueue_script(
|
||||
'ppw-cookie',
|
||||
PPW_DIR_URL . "$assert_folder/ppw-rc-form.bundle.js",
|
||||
array( 'jquery' ),
|
||||
PPW_VERSION,
|
||||
false
|
||||
);
|
||||
wp_localize_script(
|
||||
'ppw-cookie',
|
||||
'ppwContentGlobal',
|
||||
array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'restUrl' => get_rest_url(),
|
||||
'ajax_nonce' => wp_create_nonce( 'ppw_pcp_nonce' ),
|
||||
'nonce' => wp_create_nonce( 'wp_rest' ),
|
||||
'cookieExpiration' => $this->get_cookie_expiration(),
|
||||
'supportedClassNames' => apply_filters(
|
||||
'ppw_shortcode_supported_class_name',
|
||||
array(
|
||||
'defaultType' => PPW_Constants::DEFAULT_SHORTCODE_CLASS_NAME,
|
||||
)
|
||||
),
|
||||
'label' => array(
|
||||
'LOADING' => _x( 'Loading...', PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
|
||||
),
|
||||
'isUsingPCPRecaptcha' => $is_using_pcp_recaptcha
|
||||
)
|
||||
);
|
||||
|
||||
// Avoid conflict with updating post on Gutenberg when updating post.
|
||||
if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) {
|
||||
if ( $is_using_pcp_recaptcha && $count_script === 1 ) {
|
||||
add_action( 'wp_footer', function () {
|
||||
PPW_Recaptcha::get_instance()->add_recaptcha_to_head();
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether short code is valid.
|
||||
*
|
||||
* @param array $attrs Shortcode attributes.
|
||||
* @param string $content Short code content.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function is_valid_shortcode( $attrs, $content ) {
|
||||
if ( ! $this->is_supported_post_types( get_post_type() ) ) {
|
||||
/* translators: %s: Short code name */
|
||||
$message = sprintf( __( 'Our Free version [%s] shortcode doesn\'t support Custom Post Type', 'password-protect-page' ), PPW_Constants::PPW_HOOK_SHORT_CODE_NAME );
|
||||
|
||||
return apply_filters( PPW_Constants::HOOK_SHORTCODE_NOT_SUPPORT_TYPE_ERROR_MESSAGE, $message );
|
||||
}
|
||||
|
||||
/* translators: %s: Short code name */
|
||||
$message = sprintf( __( '[%s] Empty content, invalid attributes or values', 'password-protect-page' ), PPW_Constants::PPW_HOOK_SHORT_CODE_NAME );
|
||||
$message = apply_filters( PPW_Constants::HOOK_SHORT_CODE_ERROR_MESSAGE, $message );
|
||||
|
||||
if ( $this->is_empty_content( $content, $attrs ) ) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
if ( ! $this->is_valid_attributes( $attrs ) ) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attrs
|
||||
*/
|
||||
private function is_valid_date( $attrs ) {
|
||||
if ( '' !== $attrs['on'] && ! ppw_free_validate_date( $attrs['on'] ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( '' !== $attrs['off'] && ! ppw_free_validate_date( $attrs['off'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the password is valid, comparing with cookie.
|
||||
*
|
||||
* @param string $password Password.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_valid_password( $password ) {
|
||||
|
||||
$is_valid = apply_filters( 'ppw_shortcode_is_valid_password_with_cookie', false, $password, $_COOKIE );
|
||||
|
||||
if ( $is_valid ) {
|
||||
|
||||
return apply_filters( 'ppw_shortcode_after_check_is_valid_password_with_cookie', $is_valid, $password, array() );
|
||||
|
||||
}
|
||||
|
||||
$cookie_name = 'ppw_rc-' . get_the_ID();
|
||||
if ( ! isset( $_COOKIE[ $cookie_name ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
global $wp_hasher;
|
||||
$cookie_val = json_decode( wp_unslash( $_COOKIE[ $cookie_name ] ) ); // phpcs:ignore -- Here do not need to sanitize $_COOKIE data, because we use it for comparision.
|
||||
if ( ! is_array( $cookie_val ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ( $cookie_val as $val ) {
|
||||
if ( get_the_ID() !== (int) $val->post_id ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $val->passwords as $cookie_pass ) {
|
||||
if ( $wp_hasher->CheckPassword( $cookie_pass, $password ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get restricted content form.
|
||||
*
|
||||
* @param array $attrs Short-code attributes.
|
||||
* @param int $number Short-code attributes.
|
||||
*
|
||||
* @return array|mixed
|
||||
*/
|
||||
private function get_restricted_content_form( $attrs, $number ) {
|
||||
$checkbox = '';
|
||||
if ( wp_validate_boolean( $attrs['show_password'] ) ) {
|
||||
$checkbox = '<label class="ppw-pcp-checkbox-label"><input class="ppw-pcp-checkbox" type="checkbox" /> ' . _x( $this->massage_attributes( $attrs['show_password_text'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ) . '</label>';
|
||||
}
|
||||
|
||||
$desc_above_btn = '';
|
||||
if ( wp_validate_boolean( $attrs['desc_above_btn'] ) ) {
|
||||
$desc_above_btn = '<span class="ppw-pcp-pf-desc-above-btn">'._x( $this->massage_attributes( $attrs['desc_above_btn'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ).'</span>';
|
||||
}
|
||||
|
||||
// Temp hide recaptcha on section protection.
|
||||
if ( PPW_Recaptcha::get_instance()->using_pcp_recaptcha() && empty( $attrs['section'] ) ) {
|
||||
$recaptcha_input = PPW_Recaptcha::get_instance()->get_recaptcha_input();
|
||||
} else {
|
||||
$recaptcha_input = '';
|
||||
}
|
||||
|
||||
ob_start();
|
||||
include apply_filters(
|
||||
PPW_Constants::HOOK_SHORT_CODE_TEMPLATE,
|
||||
PPW_DIR_PATH . 'includes/views/shortcode/view-ppw-restriced-content-form.php'
|
||||
);
|
||||
|
||||
$form_template = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$className = '' === $attrs['class'] ? $this->get_main_class_name( $attrs ) : $this->get_main_class_name( $attrs ) . ' ' . $attrs['class'];
|
||||
|
||||
// phpcs:disable
|
||||
$form_params = array(
|
||||
PPW_Constants::SHORT_CODE_FORM_HEADLINE => _x( $this->massage_attributes( $attrs['headline'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
|
||||
PPW_Constants::SHORT_CODE_FORM_INSTRUCT => _x( $this->massage_attributes( $attrs['description'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
|
||||
PPW_Constants::SHORT_CODE_FORM_PLACEHOLDER => _x( $this->massage_attributes( $attrs['placeholder'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
|
||||
PPW_Constants::SHORT_CODE_FORM_AUTH => get_the_ID(),
|
||||
PPW_Constants::SHORT_CODE_BUTTON => _x( wp_kses_post( $attrs['button'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
|
||||
PPW_Constants::SHORT_CODE_FORM_CURRENT_URL => $this->get_the_permalink_without_cache( wp_rand( 0, 100 ) ),
|
||||
PPW_Constants::SHORT_CODE_FORM_ID => esc_attr( '' === $attrs['id'] ? get_the_ID() . wp_rand( 0, 1000 ) : wp_kses_post( $attrs['id'] ) ),
|
||||
PPW_Constants::SHORT_CODE_FORM_CLASS => esc_attr( $className ),
|
||||
PPW_Constants::SHORT_CODE_PASSWORD_LABEL => _x( $this->massage_attributes( $attrs['label'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
|
||||
PPW_Constants::SHORTCODE_ABOVE_PASSWORD_INPUT => apply_filters( 'ppw_pcp_above_password_field', '', $attrs ),
|
||||
PPW_Constants::SHORTCODE_BELOW_PASSWORD_INPUT => apply_filters( 'ppw_pcp_below_password_field', '', $attrs ),
|
||||
PPW_Constants::SHORT_CODE_FORM_ERROR_MESSAGE => '',
|
||||
PPW_Constants::SHORTCODE_DESC_ABOVE_BTN => $desc_above_btn,
|
||||
PPW_Constants::SHORTCODE_DESC_BELOW_FORM => _x( $this->massage_attributes( $attrs['desc_below_form'] ), PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
|
||||
'[PPW_PAGE]' => $number,
|
||||
'[PPW_CHECKBOX]' => $checkbox,
|
||||
'[PPW_BUTTON_LOADING]' => esc_attr_x( $attrs['loading'], PPW_Constants::CONTEXT_PCP_PASSWORD_FORM, 'password-protect-page' ),
|
||||
'[AREA]' => absint( $attrs['section'] ),
|
||||
'[PPW_RECAPTCHA_INPUT]' => $this->massage_attributes( $recaptcha_input ),
|
||||
);
|
||||
// phpcs:enable
|
||||
|
||||
foreach ( $form_params as $key => $value ) {
|
||||
$form_template = str_replace( $key, $value, $form_template );
|
||||
}
|
||||
|
||||
return $form_template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Massage attributes before showing the front end.
|
||||
*
|
||||
* @param string $val The value.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function massage_attributes( $val ) {
|
||||
return wp_kses_post( html_entity_decode( $val ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post permalink with random value
|
||||
*
|
||||
* @param int $rand_value Random value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_the_permalink_without_cache( $rand_value ) {
|
||||
return get_the_permalink() . "?action=postpass&r=$rand_value";
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate short_code attributes
|
||||
*
|
||||
* @param array $attrs Attributes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_valid_attributes( $attrs ) {
|
||||
$required_attrs = apply_filters(
|
||||
PPW_Constants::HOOK_SHORTCODE_ATTRIBUTES_VALIDATION,
|
||||
array(
|
||||
array(
|
||||
'key' => 'passwords',
|
||||
'length' => 100,
|
||||
'delimiter' => ' ',
|
||||
),
|
||||
),
|
||||
$attrs
|
||||
);
|
||||
|
||||
foreach ( $required_attrs as $attr ) {
|
||||
$val = trim( $attrs[ $attr['key'] ] );
|
||||
if ( '' === $val ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$items = explode( $attr['delimiter'], $val );
|
||||
foreach ( $items as $item ) {
|
||||
if ( $attr['length'] < strlen( $item ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $this->is_valid_date( $attrs ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalid shortcode message.
|
||||
*
|
||||
* @param string $message Error message.
|
||||
* @param array $attrs Attributes shortcode.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_invalid_shortcode_message( $message, $attrs ) {
|
||||
$color = esc_attr( PPW_Constants::PPW_ERROR_MESSAGE_COLOR );
|
||||
|
||||
return sprintf(
|
||||
'<span class="%s" style="color:%s;display: block">%s</span>',
|
||||
$this->get_main_class_name( $attrs ),
|
||||
$color,
|
||||
$message
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is whitelisted roles
|
||||
*
|
||||
* @param string $whitelisted_roles Attribute whitelist roles from shortcode.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_whitelisted_role( $whitelisted_roles ) {
|
||||
$roles = explode( ',', trim( $whitelisted_roles ) );
|
||||
foreach ( $roles as $role ) {
|
||||
$role = trim( $role );
|
||||
if ( in_array( $role, $this->supported_roles, true ) && current_user_can( $role ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is current post type supported.
|
||||
*
|
||||
* @param string $type Current post type.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_supported_post_types( $type ) {
|
||||
$is_bypass = apply_filters( PPW_Constants::HOOK_SHORTCODE_ALLOW_BYPASS_VALID_POST_TYPE, defined( 'PPW_PRO_VERSION' ) );
|
||||
if ( $is_bypass ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return in_array( $type, $this->supported_post_types, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cookie expiration
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_cookie_expiration() {
|
||||
$default = apply_filters( PPW_Constants::HOOK_COOKIE_EXPIRED, time() + 7 * DAY_IN_SECONDS );
|
||||
$setting_expiration = ppw_core_get_setting_type_string( PPW_Constants::COOKIE_EXPIRED );
|
||||
if ( empty( $setting_expiration ) ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$tmp = explode( ' ', $setting_expiration );
|
||||
if ( count( $tmp ) < 2 ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$val = $tmp[0];
|
||||
$unit = ppw_core_get_unit_time( $setting_expiration );
|
||||
|
||||
if ( 0 === $unit ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return apply_filters( PPW_Constants::HOOK_COOKIE_EXPIRED, time() + (int) $val * $unit );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the content is empty.
|
||||
*
|
||||
* @param string $content The content.
|
||||
* @param array $attrs The shortcode attributes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_empty_content( $content, $attrs ) {
|
||||
$is_empty = '' === $content;
|
||||
|
||||
return apply_filters( 'ppwp_shortcode_is_empty_content', $is_empty, $content, $attrs );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attributes from shortcode
|
||||
*
|
||||
* @param array $parsed_atts Shortcode attributes in array type.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_attributes( $parsed_atts ) {
|
||||
|
||||
// Default values for attributes.
|
||||
$default_values = array(
|
||||
'passwords' => array(),
|
||||
'cookie' => $this->get_cookie_expiration(),
|
||||
);
|
||||
|
||||
// Shortcode_parse_atts return array or empty which we only use array.
|
||||
if ( ! is_array( $parsed_atts ) ) {
|
||||
return $default_values;
|
||||
}
|
||||
|
||||
// Get passwords attribute.
|
||||
if ( isset( $parsed_atts['passwords'] ) ) {
|
||||
$default_values['passwords'] = $this->get_passwords_attribute( $parsed_atts );
|
||||
}
|
||||
|
||||
// Get cookie attribute.
|
||||
if ( isset( $parsed_atts['cookie'] ) && intval( $parsed_atts['cookie'] ) > PPW_Constants::MIN_COOKIE_EXPIRED ) {
|
||||
$default_values['cookie'] = $this->get_expired_time_cookie_attribute( $parsed_atts );
|
||||
}
|
||||
|
||||
return $default_values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert string password to array
|
||||
* Example:
|
||||
* Input: 'a b c'
|
||||
* Output: ['a','b','c']
|
||||
*
|
||||
* @param array $parsed_atts Attributes parsed.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_passwords_attribute( $parsed_atts ) {
|
||||
return array_map(
|
||||
function ( $p ) {
|
||||
return wp_specialchars_decode( $p );
|
||||
},
|
||||
explode( ' ', $parsed_atts['passwords'] )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert day to timestamp of cookie.
|
||||
*
|
||||
* @param array $parsed_atts Attributes parsed.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function get_expired_time_cookie_attribute( $parsed_atts ) {
|
||||
$hours = absint( $parsed_atts['cookie'] );
|
||||
$hours = $hours > PPW_Constants::MAX_COOKIE_EXPIRED ? PPW_Constants::MAX_COOKIE_EXPIRED : $hours;
|
||||
|
||||
return time() + $hours * HOUR_IN_SECONDS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get main class name.
|
||||
*
|
||||
* @param array $attrs Attributes shortcode.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_main_class_name( $attrs ) {
|
||||
$post_fix = empty( $attrs['type'] )
|
||||
? ''
|
||||
: '-' . $attrs['type'];
|
||||
|
||||
return $this->main_class_name . $post_fix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content for post by page number. Case use break page in content.
|
||||
*
|
||||
* @param object $post The post content.
|
||||
* @param int $page The page number.
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function get_content_by_page_number( $post, $page ) {
|
||||
if ( function_exists( 'generate_postdata' ) ) {
|
||||
$postdata = generate_postdata( $post );
|
||||
$pages = $postdata['pages'];
|
||||
} else {
|
||||
$postdata = setup_postdata( $post );
|
||||
global $pages;
|
||||
}
|
||||
|
||||
if ( false === $postdata ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $pages[ $page - 1 ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle block content on Gutenberg
|
||||
*
|
||||
* @param string $content Post content.
|
||||
*
|
||||
* @return string Content after rendered.
|
||||
*/
|
||||
public function render_block_content( $content ) {
|
||||
if ( ! function_exists( 'parse_blocks' ) ||
|
||||
! function_exists( 'has_blocks' ) ||
|
||||
! function_exists( 'render_block' )
|
||||
) {
|
||||
return $content;
|
||||
}
|
||||
if ( has_blocks( $content ) ) {
|
||||
$content_markup = '';
|
||||
$blocks = parse_blocks( $content );
|
||||
foreach ( $blocks as $block ) {
|
||||
$content_markup .= render_block( $block );
|
||||
}
|
||||
|
||||
return $content_markup;
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
if ( ! class_exists( 'PPW_Password_Subscribe' ) ) {
|
||||
class PPW_Password_Subscribe {
|
||||
|
||||
/**
|
||||
* Handle subscriber request(Call api to save data for subscriber)
|
||||
*
|
||||
* @param string $email email user request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function handle_subscribe_request( $email ) {
|
||||
$ppw_config = include PPW_DIR_PATH . 'config.php';
|
||||
$data = array(
|
||||
'email' => $email,
|
||||
'plugin' => 'ppwp',
|
||||
);
|
||||
$args = array(
|
||||
'body' => json_encode( $data ),
|
||||
'timeout' => '100',
|
||||
'redirection' => '5',
|
||||
'httpversion' => '1.0',
|
||||
'blocking' => true,
|
||||
'headers' => array(
|
||||
'Content-Type' => 'application/json',
|
||||
),
|
||||
);
|
||||
$response = wp_remote_post(
|
||||
$ppw_config->subscribe_api,
|
||||
$args
|
||||
);
|
||||
$status_code = absint( wp_remote_retrieve_response_code( $response ) );
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return array(
|
||||
'error_message' => $response->get_error_message(),
|
||||
);
|
||||
} else if ( $status_code >= 400 ) {
|
||||
return array(
|
||||
'error_message' => __('Invalid email address', 'password-protect-page'),
|
||||
);
|
||||
} else {
|
||||
update_user_meta( get_current_user_id(), PPW_Constants::USER_SUBSCRIBE, true );
|
||||
return array(
|
||||
'data' => json_decode( wp_remote_retrieve_body( $response ) ),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* PPWP Lite: Category Protection
|
||||
*/
|
||||
?>
|
||||
|
||||
<h2 class="ppw-cat__title"> <?php echo esc_html__('PPWP Lite: Category Protection','password-protect-page');?></h2>
|
||||
<form method="post" id="ppwp_protect_category_form" class="ppw-cat__form">
|
||||
<input type="hidden" id="ppw_category_form_nonce" value="<?php echo esc_attr( wp_create_nonce(PPW_Constants::GENERAL_FORM_NONCE) ); ?>" />
|
||||
<div class="form__option-wrapper">
|
||||
<span class="form__option-switch-btn">
|
||||
<label class="pda_switch ppw-switch__wrapper" for="ppwp_is_protect_category">
|
||||
<input type="checkbox" id="ppwp_is_protect_category" <?php echo $is_protect ? 'checked' : '' ?> />
|
||||
<span class="pda-slider round ppw-switch--btn"></span>
|
||||
</label>
|
||||
</span>
|
||||
<span class="form__option-label">
|
||||
<?php echo esc_html__('Password Protect Categories', 'password-protect-page') ?>
|
||||
</span>
|
||||
</div>
|
||||
<p class="form__desc"><?php echo wp_kses_post( sprintf( '<a target="_blank" rel="noreferrer noopener" href="%1$s">%2$s</a> %3$s <a href="%4$s">%5$s</a>.', 'https://passwordprotectwp.com/docs/password-protect-wordpress-categories/?utm_source=user-website&utm_medium=category-protection&utm_campaign=ppwp-free', __( 'Protect all posts under protected categories', 'password-protect-page' ), __( 'with a single password. Customize the password form using', 'password-protect-page' ), admin_url( 'customize.php?autofocus[panel]=ppwp' ), __( 'WordPress Customizer', 'password-protect-page' ) ) ); ?></p>
|
||||
<p class="form__select-wrapper form__input-wrapper">
|
||||
<label class="form__label form__label-cats" for="ppwp-cat-select"><?php echo esc_html__('Select your private categories', 'password-protect-page') ?></label>
|
||||
<select class="form__select" id="ppwp_protected_categories_selected" multiple="multiple">
|
||||
<?php
|
||||
foreach ($categories as $category) {
|
||||
$selected = in_array($category->term_id, $protected_categories) ? 'selected' : '';
|
||||
echo '<option ' . esc_attr( $selected ) . ' value="' . esc_attr( $category->term_id ) . '">' . esc_html( $category->name ) . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<div id="ppwp_error_protected_categories_selected" style="display: none; color: red; position: absolute; font-size: 12px;">This field is required.</div>
|
||||
</p>
|
||||
<p class="form__input-wrapper">
|
||||
<label class="form__label form__label__pass" for="ppwp_categories_password"><?php echo esc_html__('Set a password', 'password-protect-page') ?></label>
|
||||
<input class="form__input" id="ppwp_categories_password" type="text" placeholder="Enter a password" value="<?php echo esc_html( $password ) ?>">
|
||||
<div id="ppwp_error_categories_password" style="display: none; color: red; position: absolute; font-size: 12px;">This field is required.</div>
|
||||
</p>
|
||||
<p class="form__btn-wrapper">
|
||||
<input type="submit" name="submit" id="ppwp-submit" class="button button-primary" value="Save Changes">
|
||||
</p>
|
||||
</form>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Password Protected Service
|
||||
*/
|
||||
$service = new PPW_Password_Services();
|
||||
$is_protected = $service->is_protected_content( $post_id );
|
||||
$icon_class = $is_protected ? 'dashicons-lock' : 'dashicons-unlock';
|
||||
$color_class = $is_protected ? 'ppw_protected_color' : 'ppw_unprotected_color';
|
||||
$status = $is_protected ? 'protected' : 'unprotected';
|
||||
$post = get_post( $post_id );
|
||||
?>
|
||||
|
||||
<div class="ppw-column">
|
||||
<span id="ppw-badge-protection_<?php echo esc_attr( $post_id ); ?>"
|
||||
class="ppw-badge-protection <?php echo esc_attr( $color_class ); ?>">
|
||||
<i class="dashicons <?php echo esc_attr( $icon_class ); ?>"></i> <?php echo esc_html( $status, 'password-protect-page' ); ?>
|
||||
</span>
|
||||
</div>
|
||||
2
wp-content/plugins/password-protect-page/includes/views/dist/ppw-category.css
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.ppw-cat__form{padding-bottom:0rem;margin-bottom:2rem;border-bottom:1px solid #bbb}.ppw-cat__form .ppw-switch__wrapper{margin:0 7px 0 0}.form__option-wrapper{display:flex;align-items:center}.form__option-wrapper .form__option-label{font-size:15px}.form__input-wrapper label{display:block;padding:2px 0}.form__input-wrapper input{width:95%}.form__input-wrapper{margin-bottom:2px !important}.form__btn-wrapper{margin-top:30px}.form__label__pass{margin-top:22px}
|
||||
|
||||
1
wp-content/plugins/password-protect-page/includes/views/dist/ppw-category.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e){var t={};function r(p){if(t[p])return t[p].exports;var o=t[p]={i:p,l:!1,exports:{}};return e[p].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,p){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:p})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var p=Object.create(null);if(r.r(p),Object.defineProperty(p,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(p,o,function(t){return e[t]}.bind(null,o));return p},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=8)}({8:function(e,t,r){"use strict";r.r(t);r(9);!function(e){e(function(){e("#ppwp_protected_categories_selected").select2({width:"95%"}),e("#ppwp_is_protect_category").change(function(){e(this).prop("checked")?(e(".form__input-wrapper").show(),e("#ppwp_categories_password").trigger("change")):(e(".form__input-wrapper").hide(),e("#ppwp_error_categories_password").hide(),e("#ppwp_error_protected_categories_selected").hide())}),e("#ppwp_is_protect_category").trigger("change"),e("#ppwp_protect_category_form").submit(function(t){t.preventDefault();var r=e("#ppwp_categories_password").val(),p=e("#ppwp_protected_categories_selected").val(),o=e("#ppwp_is_protect_category").prop("checked");o&&""===r?e(this).find("#ppwp_error_categories_password").show():e(this).find("#ppwp_error_categories_password").hide(),o&&0===p.length?e(this).find("#ppwp_error_protected_categories_selected").show():e(this).find("#ppwp_error_protected_categories_selected").hide();var c={ppwp_is_protect_category:e("#ppwp_is_protect_category").prop("checked"),ppwp_categories_password:e("#ppwp_categories_password").val(),ppwp_protected_categories_selected:e("#ppwp_protected_categories_selected").val()};c.ppwp_categories_password=c.ppwp_categories_password.trim(),(!o||""!==r&&0!==p.length)&&(e("#ppwp-submit").prop("disabled",!0),function(t,r){!function(t,r){e.ajax({url:ppw_category_data.ajax_url,type:"POST",data:t,timeout:5e3,success:function(e){r(e,null)},error:function(e){r(null,e)}})}({action:"ppw_free_update_category_settings",settings:t,security_check:e("#ppw_category_form_nonce").val()},r)}(c,function(t,r){t&&(toastr.success("Great! Your settings have been updated successfully.","PPWP Lite"),setTimeout(function(){window.location.reload()},700)),r&&(400===r.status?toastr.error(r.responseJSON.message,"PPWP Lite"):toastr.error("Oops! Something went wrong. Please try again.","PPWP Lite")),e("#ppwp-submit").prop("disabled",!1)}))})})}(jQuery)},9:function(e,t,r){}});
|
||||
1
wp-content/plugins/password-protect-page/includes/views/dist/ppw-entire-site.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e){var r={};function t(s){if(r[s])return r[s].exports;var p=r[s]={i:s,l:!1,exports:{}};return e[s].call(p.exports,p,p.exports,t),p.l=!0,p.exports}t.m=e,t.c=r,t.d=function(e,r,s){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:s})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(t.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var p in e)t.d(s,p,function(r){return e[r]}.bind(null,p));return s},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=2)}([function(e,r,t){"use strict";r.a=function(e){e("#ppw_subscribe_form").submit(function(r){r.preventDefault();const t=e("#ppw_email_subscribe").val().trim();/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t)?(e("#ppw_subscribe_button").val("Saving..."),function(e,r,t){var s={action:"ppw_free_subscribe_request",settings:r,security_check:e("#ppw_subscribe_form_nonce").val()};!function(e,r,t){let s=!1;window.ppw_general_data?s=ppw_general_data.ajax_url:window.ppw_entire_site_data&&(s=ppw_entire_site_data.ajax_url),s&&e.ajax({url:s,type:"POST",data:r,timeout:5e3,success:function(e){t(e,null)},error:function(e){t(null,e)}})}(e,s,t)}(e,{ppw_email:t},function(r,t){r?(e("#ppw_subscribe_form").hide(),e("#ppw_subscribe_form_success").show()):t&&(400===t.status?(e(".ppw_subscribe_error").text(t.responseJSON.message),e(".ppw_subscribe_error").show("slow")):(e(".ppw_subscribe_error").text("Oops! Something went wrong. Please reload the page and try again."),e(".ppw_subscribe_error").show("slow"))),e("#ppw_subscribe_button").val("Get Lucky")})):(e(".ppw_subscribe_error").show("slow"),e("#ppw_email_subscribe").focus(),e("#ppw_subscribe_button").val("Get Lucky"))})}},,function(e,r,t){"use strict";t.r(r);var s=t(0);!function(e){e(function(){e(".ppwp_select2").select2({width:"100%"}),e("#ppwp_free_switch_exclude_page").change(function(){e(this).prop("checked")?e(".ppwp_free_wrap_select_exclude_page").show():e(".ppwp_free_wrap_select_exclude_page").hide()}),e("#ppwp_free_switch_exclude_page").trigger("change"),e("#ppwp_apply_password_for_entire_site").change(function(){e(this).prop("checked")?(e(".ppwp_logic_show_input_password").show(),e("#ppwp_password_for_entire_site").attr("required",!0),e("#ppwp_password_for_entire_site").trigger("change")):(e(".ppwp_logic_show_input_password").hide(),e("#submit").prop("disabled",!1),e("#ppwp_password_for_entire_site").attr("required",!1))}),e("#ppwp_apply_password_for_entire_site").trigger("change"),e("#ppwp_set_new_password_for_entire_site").change(function(){e(this).prop("checked")?(e("#ppwp_new_password_entire_site").show(),e("#ppwp_password_for_entire_site").attr("required",!0)):(e("#ppwp_new_password_entire_site").hide(),e("#ppwp_password_for_entire_site").val(""),e("#submit").prop("disabled",!1),e("#ppwp_password_for_entire_site").attr("required",!1))}),e("#ppwp_set_new_password_for_entire_site").trigger("change"),e("#ppwp_password_for_entire_site").change(function(){-1!==e(this).val().indexOf(" ")?(toastr.error("Please remove spaces in password!","Password Protect WordPress"),e("#submit").prop("disabled",!0)):e("#submit").prop("disabled",!1)}),e("#ppwp_password_for_entire_site").trigger("change"),Object(s.a)(e),e("#ppw_entire_site_form").submit(function(r){r.preventDefault(),function(r,t){!function(r,t){e("#submit").prop("disabled",!0),e.ajax({url:ppw_entire_site_data.ajax_url,type:"POST",data:r,success:function(e){t(e,null)},error:function(e){t(null,e)},timeout:5e3})}({action:"ppw_free_update_entire_site_settings",settings:r,security_check:e("#ppw_entire_site_form_nonce").val()},t)}({ppwp_apply_password_for_entire_site:e("#ppwp_apply_password_for_entire_site").prop("checked"),password_for_website:e("#ppwp_password_for_entire_site").val(),ppwp_set_new_password_for_entire_site:e("#ppwp_set_new_password_for_entire_site").prop("checked")},function(r,t){r&&(toastr.success("Great! Your settings have been updated successfully.","PPWP Lite"),location.reload(!0)),t&&(400===t.status?toastr.error(t.responseJSON.message,"PPWP Lite"):toastr.error("Oops! Something went wrong. Please try again.","PPWP Lite"),console.log("Data error",t),e("#submit").prop("disabled",!1))})})})}(jQuery)}]);
|
||||
1
wp-content/plugins/password-protect-page/includes/views/dist/ppw-external-configuration.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e){var r={};function t(p){if(r[p])return r[p].exports;var a=r[p]={i:p,l:!1,exports:{}};return e[p].call(a.exports,a,a.exports,t),a.l=!0,a.exports}t.m=e,t.c=r,t.d=function(e,r,p){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:p})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var p=Object.create(null);if(t.r(p),Object.defineProperty(p,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var a in e)t.d(p,a,function(r){return e[r]}.bind(null,a));return p},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=6)}({0:function(e,r,t){"use strict";r.a=function(e){e("#ppw_subscribe_form").submit(function(r){r.preventDefault();const t=e("#ppw_email_subscribe").val().trim();/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t)?(e("#ppw_subscribe_button").val("Saving..."),function(e,r,t){var p={action:"ppw_free_subscribe_request",settings:r,security_check:e("#ppw_subscribe_form_nonce").val()};!function(e,r,t){let p=!1;window.ppw_general_data?p=ppw_general_data.ajax_url:window.ppw_entire_site_data&&(p=ppw_entire_site_data.ajax_url),p&&e.ajax({url:p,type:"POST",data:r,timeout:5e3,success:function(e){t(e,null)},error:function(e){t(null,e)}})}(e,p,t)}(e,{ppw_email:t},function(r,t){r?(e("#ppw_subscribe_form").hide(),e("#ppw_subscribe_form_success").show()):t&&(400===t.status?(e(".ppw_subscribe_error").text(t.responseJSON.message),e(".ppw_subscribe_error").show("slow")):(e(".ppw_subscribe_error").text("Oops! Something went wrong. Please reload the page and try again."),e(".ppw_subscribe_error").show("slow"))),e("#ppw_subscribe_button").val("Get Lucky")})):(e(".ppw_subscribe_error").show("slow"),e("#ppw_email_subscribe").focus(),e("#ppw_subscribe_button").val("Get Lucky"))})}},6:function(e,r,t){"use strict";t.r(r);var p=t(0);!function(e){function r(r,t){!function(r,t){e.ajax({url:ppw_external_data.ajax_url,type:"POST",data:r,timeout:5e3,success:function(e){t(e,null)},error:function(e){t(null,e)}})}({action:"ppw_free_update_external_settings",settings:r,security_check:e("#ppw_general_form_nonce").val()},t)}e(function(){Object(p.a)(e),e("#wpp_external_v2_form").submit(function(t){t.preventDefault();var p=e("#wpp_recaptcha_v2_checkbox_api_key").val().trim(),a=e("#wpp_recaptcha_v2_checkbox_api_secret").val().trim();if(a?e(this).find("#ppwp-error-require-v2-secret").hide():(e(this).find("#ppwp-error-require-v2-secret").show(),e(this).find("#wpp_recaptcha_v2_checkbox_api_secret").focus()),p?e(this).find("#ppwp-error-require-v2-key").hide():(e(this).find("#ppwp-error-require-v2-key").show(),e(this).find("#wpp_recaptcha_v2_checkbox_api_key").focus()),""!==p&&""!==a){r({wpp_recaptcha_v2_checkbox_api_key:e("#wpp_recaptcha_v2_checkbox_api_key").val(),wpp_recaptcha_v2_checkbox_api_secret:e("#wpp_recaptcha_v2_checkbox_api_secret").val()},function(r,t){r&&(toastr.success("Great! Your settings have been updated successfully.","PPWP Lite"),location.reload(!0)),t&&(400===t.status?toastr.error(t.responseJSON.message,"PPWP Lite"):toastr.error("Oops! Something went wrong. Please try again!","PPWP Lite"),e("#v2_submit_btn").prop("disabled",!1))})}})}),e(function(){Object(p.a)(e),e("#wpp_external_v3_form").submit(function(t){t.preventDefault();var p=e("#wpp_recaptcha_api_key").val().trim(),a=e("#wpp_recaptcha_api_secret").val().trim();if(a?e(this).find("#ppwp-error-require-v3-secret").hide():(!1,e(this).find("#ppwp-error-require-v3-secret").show(),e(this).find("#wpp_recaptcha_api_secret").focus()),p?e(this).find("#ppwp-error-require-v3-key").hide():(!1,e(this).find("#ppwp-error-require-v3-key").show(),e(this).find("#wpp_recaptcha_api_key").focus()),""!==p&&""!==a){r({wpp_recaptcha_api_key:e("#wpp_recaptcha_api_key").val(),wpp_recaptcha_api_secret:e("#wpp_recaptcha_api_secret").val(),wpp_recaptcha_score:e("#wpp_recaptcha_score").val()},function(r,t){r&&(toastr.success("Great! Your settings have been updated successfully.","PPWP Lite"),location.reload(!0)),t&&(400===t.status?toastr.error(t.responseJSON.message,"PPWP Lite"):toastr.error("Oops! Something went wrong. Please try again!","PPWP Lite"),e("#v3_submit_btn").prop("disabled",!1))})}})})}(jQuery)}});
|
||||
1
wp-content/plugins/password-protect-page/includes/views/dist/ppw-external.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,r),s.l=!0,s.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(n,s,function(t){return e[t]}.bind(null,s));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=5)}({0:function(e,t,r){"use strict";t.a=function(e){e("#ppw_subscribe_form").submit(function(t){t.preventDefault();const r=e("#ppw_email_subscribe").val().trim();/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(r)?(e("#ppw_subscribe_button").val("Saving..."),function(e,t,r){var n={action:"ppw_free_subscribe_request",settings:t,security_check:e("#ppw_subscribe_form_nonce").val()};!function(e,t,r){let n=!1;window.ppw_general_data?n=ppw_general_data.ajax_url:window.ppw_entire_site_data&&(n=ppw_entire_site_data.ajax_url),n&&e.ajax({url:n,type:"POST",data:t,timeout:5e3,success:function(e){r(e,null)},error:function(e){r(null,e)}})}(e,n,r)}(e,{ppw_email:r},function(t,r){t?(e("#ppw_subscribe_form").hide(),e("#ppw_subscribe_form_success").show()):r&&(400===r.status?(e(".ppw_subscribe_error").text(r.responseJSON.message),e(".ppw_subscribe_error").show("slow")):(e(".ppw_subscribe_error").text("Oops! Something went wrong. Please reload the page and try again."),e(".ppw_subscribe_error").show("slow"))),e("#ppw_subscribe_button").val("Get Lucky")})):(e(".ppw_subscribe_error").show("slow"),e("#ppw_email_subscribe").focus(),e("#ppw_subscribe_button").val("Get Lucky"))})}},5:function(e,t,r){"use strict";r.r(t);var n=r(0);!function(e){e(function(){e(".ppw_select_types").select2({width:"100%"}),e("#wpp_use_recaptcha").change(function(){e(this).prop("checked")?(e("#wpp_recaptcha_options").show(),e("#wpp_recaptcha_password_types").attr("required",!0)):(e("#wpp_recaptcha_options").hide(),e("#wpp_recaptcha_password_types").attr("required",!1))}),Object(n.a)(e),e("#wpp_external_form").submit(function(t){t.preventDefault(),function(t,r){var n={action:"ppw_free_update_external_settings",settings:t,security_check:e("#ppw_general_form_nonce").val()};e("#submit").prop("disabled",!0),function(t,r){e.ajax({url:ppw_external_data.ajax_url,type:"POST",data:t,timeout:5e3,success:function(e){r(e,null)},error:function(e){r(null,e)}})}(n,r)}(function(){var t=e("#wpp_use_recaptcha").prop("checked"),r={wpp_use_recaptcha:t};t&&(r.wpp_recaptcha_type=e("#wpp_recaptcha_type").val(),r.wpp_recaptcha_password_types=e("#wpp_recaptcha_password_types").val());return r}(),function(t,r){if(t)return toastr.success("Great! Your settings have been updated successfully.","PPWP Lite"),void location.reload(!0);r&&(400===r.status?toastr.error(r.responseJSON.message,"PPWP Lite"):toastr.error("Oops! Something went wrong. Please try again.","PPWP Lite"),e("#submit").prop("disabled",!1))})})})}(jQuery)}});
|
||||