abilities
1 month ago
admin
1 month ago
compatibility
1 month ago
extensions
1 month ago
foopluginbase
1 month ago
public
1 month ago
thumbs
1 month ago
asset-manifest.php
1 month ago
class-attachment-filters.php
1 month ago
class-command-palette.php
1 month ago
class-foogallery-animated-gif-support.php
1 month ago
class-foogallery-attachment-custom-class.php
1 month ago
class-foogallery-attachment-filename.php
1 month ago
class-foogallery-attachment-type.php
1 month ago
class-foogallery-attachment.php
1 month ago
class-foogallery-cache.php
1 month ago
class-foogallery-common-fields.php
1 month ago
class-foogallery-crop-position.php
1 month ago
class-foogallery-datasource-media_library.php
1 month ago
class-foogallery-debug.php
1 month ago
class-foogallery-delayed-runtime-loader.php
1 month ago
class-foogallery-extensions-compatibility.php
1 month ago
class-foogallery-force-https.php
1 month ago
class-foogallery-lazyload.php
1 month ago
class-foogallery-license-constant-handler.php
1 month ago
class-foogallery-lightbox.php
1 month ago
class-foogallery-paging.php
1 month ago
class-foogallery-password-protect.php
1 month ago
class-foogallery-sitemaps.php
1 month ago
class-foogallery-widget.php
1 month ago
class-foogallery.php
1 month ago
class-gallery-advanced-settings.php
1 month ago
class-il8n.php
1 month ago
class-override-thumbnail.php
1 month ago
class-posttypes.php
1 month ago
class-previews.php
1 month ago
class-retina.php
1 month ago
class-thumbnail-dimensions.php
1 month ago
class-thumbnails.php
1 month ago
class-version-check.php
1 month ago
constants.php
1 month ago
functions.php
1 month ago
gallery-management-functions.php
1 month ago
includes.php
1 month ago
index.php
1 month ago
render-functions.php
1 month ago
class-foogallery-password-protect.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Class used to handle password protected galleries. |
| 9 | */ |
| 10 | if ( ! class_exists( 'FooGallery_Password_Protect' ) ) { |
| 11 | |
| 12 | class FooGallery_Password_Protect { |
| 13 | |
| 14 | function __construct() { |
| 15 | add_filter( 'the_password_form', array( $this, 'customize_password_form_for_galleries' ), 10, 3 ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Customize the password form when used for a gallery. |
| 20 | * |
| 21 | * @param string $output The default password form HTML |
| 22 | * @param WP_Post $post The post object |
| 23 | * @param string $invalid_password The invalid password message |
| 24 | * @return string Modified password form HTML |
| 25 | */ |
| 26 | public function customize_password_form_for_galleries( $output, $post, $invalid_password = '') { |
| 27 | global $current_foogallery; |
| 28 | |
| 29 | if ( empty( $current_foogallery ) ) { |
| 30 | return $output; |
| 31 | } |
| 32 | |
| 33 | // Check if we're in gallery context |
| 34 | $gallery = foogallery::get( $post ); |
| 35 | |
| 36 | if ( !empty( $gallery ) && $current_foogallery->ID === $gallery->ID ) { |
| 37 | // Get current URL for form action |
| 38 | $current_url = ''; |
| 39 | if ( isset( $_SERVER['REQUEST_URI'] ) ) { |
| 40 | $current_url = esc_url_raw( $_SERVER['REQUEST_URI'] ); |
| 41 | } |
| 42 | |
| 43 | // Replace the redirect_to hidden input value with current URL |
| 44 | $output = preg_replace( |
| 45 | '/<input type="hidden" name="redirect_to" value="[^"]*" \/>/', |
| 46 | '<input type="hidden" name="redirect_to" value="' . esc_attr( $current_url ) . '" />', |
| 47 | $output |
| 48 | ); |
| 49 | |
| 50 | // Replace the default text with gallery-specific text |
| 51 | $output = str_replace( |
| 52 | __( 'This content is password protected. To view it please enter your password below:' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain |
| 53 | __( 'This gallery is password protected. To view it please enter your password below:', 'foogallery' ), |
| 54 | $output |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | return $output; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 |