Plugin Directory

Changeset 1397531


Ignore:
Timestamp:
04/17/2016 03:09:39 AM (10 years ago)
Author:
maratbn
Message:

Latest updates from the 'master' branch from the official repo, which is at: https://github.com/maratbn/LoginRequirePress

Location:
loginrequirepress/trunk
Files:
1 added
5 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • loginrequirepress/trunk/LICENSE

    r1193830 r1397531  
    2828  http://www.maratbn.com/projects/login-require-press
    2929
    30   Copyright (C) 2015  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
     30  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    3131
    32   Version:        0.1.3-development_unreleased
     32  Version:        1.1.0-development_unreleased
    3333
    34   Module:         LICENSE
     34  Module:         loginrequirepress/LICENSE
    3535
    3636  Description:    License for LoginRequirePress.
  • loginrequirepress/trunk/LoginRequirePress.php

    r1193830 r1397531  
    99  Author URI: http://www.maratbn.com
    1010  License: GPL3
    11   Version: 0.1.3-development_unreleased
     11  Version: 1.1.0-development_unreleased
    1212  Text Domain: domain-plugin-LoginRequirePress
    1313*/
     
    4343  http://www.maratbn.com/projects/login-require-press
    4444
    45   Copyright (C) 2015  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
    46 
    47   Version:        0.1.3-development_unreleased
     45  Copyright (C) 2015-2016  Marat Nepomnyashy  http://maratbn.com  maratbn@gmail
     46
     47  Version:        1.1.0-development_unreleased
    4848
    4949  Module:         LoginRequirePress.php
     
    7272
    7373
     74    const PHP_VERSION_MIN_SUPPORTED = '5.4';
     75
    7476    const LOGIN_REQUIRE_PRESS     = 'login_require_press';
    7577    const YES                     = 'yes';
    7678
    77     add_action('admin_menu', '\\plugin_LoginRequirePress\\action_admin_menu');
    78     add_action('admin_post_plugin_LoginRequirePress_settings',
    79                '\\plugin_LoginRequirePress\\action_admin_post_plugin_LoginRequirePress_settings');
    80     add_action('send_headers', '\\plugin_LoginRequirePress\\action_send_headers');
    81 
    82     add_filter('plugin_action_links_' . plugin_basename(__FILE__),
     79    \add_action('admin_menu', '\\plugin_LoginRequirePress\\action_admin_menu');
     80    \add_action('admin_post_plugin_LoginRequirePress_settings',
     81                '\\plugin_LoginRequirePress\\action_admin_post_plugin_LoginRequirePress_settings');
     82    \add_action('send_headers', '\\plugin_LoginRequirePress\\action_send_headers');
     83
     84    \add_filter('plugin_action_links_' . \plugin_basename(__FILE__),
    8385                                        '\\plugin_LoginRequirePress\\filter_plugin_action_links');
    84     add_filter('posts_results', '\\plugin_LoginRequirePress\\filter_posts_results');
     86    \add_filter('posts_results', '\\plugin_LoginRequirePress\\filter_posts_results');
     87
     88    \register_activation_hook(__FILE__, '\\plugin_LoginRequirePress\\plugin_activation_hook');
    8589
    8690
    8791    function action_admin_menu() {
    88         add_options_page( __('LoginRequirePress Settings', 'domain-plugin-LoginRequirePress'),
    89                           __('LoginRequirePress', 'domain-plugin-LoginRequirePress'),
     92        \add_options_page(\__('LoginRequirePress Settings', 'domain-plugin-LoginRequirePress'),
     93                          \__('LoginRequirePress', 'domain-plugin-LoginRequirePress'),
    9094                          'manage_options',
    9195                          'plugin_LoginRequirePress_settings',
     
    9599    function action_admin_post_plugin_LoginRequirePress_settings() {
    96100        //  Based on: http://jaskokoyn.com/2013/03/26/wordpress-admin-forms/
    97         if (!current_user_can('manage_options')) {
    98             wp_die(__('Insufficient user permissions to modify options.',
    99                       'domain-plugin-LoginRequirePress'));
     101        if (!\current_user_can('manage_options')) {
     102            \wp_die(\__('Insufficient user permissions to modify options.',
     103                        'domain-plugin-LoginRequirePress'));
    100104        }
    101105
    102106        // Check that nonce field
    103         check_admin_referer('plugin_LoginRequirePress_settings_nonce');
     107        \check_admin_referer('plugin_LoginRequirePress_settings_nonce');
    104108
    105109        foreach ($_POST as $strFieldName => $strFieldValue) {
    106             preg_match('/^post_(\d+)$/', $strFieldName, $arrMatch);
    107             if ($arrMatch && count($arrMatch) == 2) {
     110            \preg_match('/^post_(\d+)$/', $strFieldName, $arrMatch);
     111            if ($arrMatch && \count($arrMatch) == 2) {
    108112                $idPost = $arrMatch[1];
    109113                $flagIsLocked = isset($_POST['lock_' . $idPost]);
     
    116120        }
    117121
    118         wp_redirect(getUrlSettings());
     122        \wp_redirect(getUrlSettings());
    119123        exit();
    120124    }
     
    123127
    124128        //  No need to redirect to the login page if the user is already logged in.
    125         if (is_user_logged_in()) return;
     129        if (\is_user_logged_in()) return;
    126130
    127131        global $wp;
     
    144148                $w_p_query->the_post();
    145149                if (isLoginRequiredForPost($post)) {
    146                     \header('Location: ' . wp_login_url(home_url($_SERVER['REQUEST_URI'])));
     150                    \header('Location: ' . \wp_login_url(\home_url($_SERVER['REQUEST_URI'])));
    147151                    exit(0);
    148152                }
    149153            }
    150             wp_reset_postdata();
     154            \wp_reset_postdata();
    151155        }
    152156    }
    153157
    154158    function filter_plugin_action_links($arrLinks) {
    155         array_push($arrLinks,
    156                    '<a href=\'' . getUrlSettings() . '\'>'
    157                                     . __('Settings', 'domain-plugin-LoginRequirePress') . '</a>');
     159        \array_push($arrLinks,
     160                    '<a href=\'' . getUrlSettings() . '\'>'
     161                                   . \__('Settings', 'domain-plugin-LoginRequirePress') . '</a>');
    158162        return $arrLinks;
    159163    }
     
    174178            if (isLoginRequiredForPost($post)) {
    175179                if ($flagIsSearchNotLoggedIn) {
    176                     $post->post_content = __('[Post content protected by LoginRequirePress.  Login to see the content.]',
    177                                              'domain-plugin-LoginRequirePress');
    178                     $post->post_title = __('[Post title protected by LoginRequirePress.  Login to see the title.]',
    179                                            'domain-plugin-LoginRequirePress');
     180                    $post->post_content = \__('[Post content protected by LoginRequirePress.  Login to see the content.]',
     181                                              'domain-plugin-LoginRequirePress');
     182                    $post->post_title = \__('[Post title protected by LoginRequirePress.  Login to see the title.]',
     183                                            'domain-plugin-LoginRequirePress');
    180184                } else {
    181185                    continue;
     
    183187            }
    184188
    185             array_push($arrPostsFiltered, $post);
     189            \array_push($arrPostsFiltered, $post);
    186190        }
    187191
     
    190194
    191195    function getUrlSettings() {
    192         return admin_url('options-general.php?page=plugin_LoginRequirePress_settings');
     196        return \admin_url('options-general.php?page=plugin_LoginRequirePress_settings');
    193197    }
    194198
    195199    function isLoginRequiredForPost(&$post) {
    196         return (strcasecmp(YES, \get_post_meta($post->ID,
    197                                                LOGIN_REQUIRE_PRESS,
    198                                                true)) == 0);
     200        return (\strcasecmp(YES, \get_post_meta($post->ID,
     201                                                LOGIN_REQUIRE_PRESS,
     202                                                true)) == 0);
     203    }
     204
     205    function plugin_activation_hook() {
     206         if (\version_compare(\strtolower(PHP_VERSION), PHP_VERSION_MIN_SUPPORTED, '<')) {
     207            \wp_die(
     208                \sprintf(\__('LoginRequirePress plugin cannot be activated because the currently active PHP version on this server is < %s and not supported.  PHP version >= %s is required.',
     209                             'domain-plugin-LoginRequirePress'),
     210                         PHP_VERSION_MIN_SUPPORTED));
     211        }
    199212    }
    200213
    201214    function render_settings() {
    202215        //  Based on http://codex.wordpress.org/Administration_Menus
    203         if (!current_user_can('manage_options' ))  {
    204             wp_die(__('You do not have sufficient permissions to access this page.',
    205                       'domain-plugin-LoginRequirePress'));
     216        if (!\current_user_can('manage_options' ))  {
     217            \wp_die(\__('You do not have sufficient permissions to access this page.',
     218                        'domain-plugin-LoginRequirePress'));
    206219        }
    207220    ?><div class="wrap"><?php
    208       ?><p><?=sprintf(
    209         __('Check the checkbox(es) corresponding to the post(s) for which you want to require ' .
    210            'user login, then submit the form by clicking \'%1$s\' at the top or bottom.',
    211            'domain-plugin-LoginRequirePress'),
    212         __('Update LR Settings',
    213            'domain-plugin-LoginRequirePress'));
     221      ?><p><?=\sprintf(
     222        \__('Check the checkbox(es) corresponding to the post(s) for which you want to require ' .
     223            'user login, then submit the form by clicking \'%1$s\' at the top or bottom.',
     224            'domain-plugin-LoginRequirePress'),
     225        \__('Update LR Settings',
     226            'domain-plugin-LoginRequirePress'));
    214227             ?></p><?php
    215228      ?><form method='post' action='admin-post.php'><?php
    216229        ?><input type='hidden' name='action' value='plugin_LoginRequirePress_settings' /><?php
    217           wp_nonce_field('plugin_LoginRequirePress_settings_nonce');
     230          \wp_nonce_field('plugin_LoginRequirePress_settings_nonce');
    218231
    219232          $w_p_query = new \WP_Query(['order'           => 'ASC',
     
    225238          global $post;
    226239          if ($w_p_query->have_posts()) {
    227           ?><input type='submit' value='<?=__('Update LR Settings',
    228                                               'domain-plugin-LoginRequirePress')
     240              $arrNonPrivateLoginProtected = [];
     241              $arrPrivate = [];
     242              $arrPasscodeProtected = [];
     243          ?><input type='submit' value='<?=\__('Update LR Settings',
     244                                               'domain-plugin-LoginRequirePress')
    229245                                          ?>' class='button-primary'/><hr><?php
    230246          ?><table style='border-collapse:collapse'><?php
    231247            ?><tr><?php
    232248              ?><th style='padding-right:15px;text-align:left'><?=
    233                 __('LR', 'domain-plugin-LoginRequirePress')
    234               ?></th><?php
    235               ?><th style='padding-right:15px;text-align:left'><?=
    236                 __('Current LR', 'domain-plugin-LoginRequirePress')
    237               ?></th><?php
    238               ?><th style='padding-right:15px;text-align:left'><?=
    239                 __('ID', 'domain-plugin-LoginRequirePress')
    240               ?></th><?php
    241               ?><th style='padding-right:15px;text-align:left'><?=
    242                 __('Post Name', 'domain-plugin-LoginRequirePress')
    243               ?></th><?php
    244               ?><th style='padding-right:15px;text-align:left'><?=
    245                 __('Post Type', 'domain-plugin-LoginRequirePress')
    246               ?></th><?php
    247               ?><th style='padding-right:15px;text-align:left'><?=
    248                 __('Page Template', 'domain-plugin-LoginRequirePress')
    249               ?></th><?php
    250               ?><th style='padding-right:15px;text-align:left'><?=
    251                 __('Post Status', 'domain-plugin-LoginRequirePress')
     249                \__('LR', 'domain-plugin-LoginRequirePress')
     250              ?></th><?php
     251              ?><th style='padding-right:15px;text-align:left'><?=
     252                \__('Current LR', 'domain-plugin-LoginRequirePress')
     253              ?></th><?php
     254              ?><th style='padding-right:15px;text-align:left'><?=
     255                \__('ID', 'domain-plugin-LoginRequirePress')
     256              ?></th><?php
     257              ?><th style='padding-right:15px;text-align:left'><?=
     258                \__('Post Name', 'domain-plugin-LoginRequirePress')
     259              ?></th><?php
     260              ?><th style='padding-right:15px;text-align:left'><?=
     261                \__('Post Type', 'domain-plugin-LoginRequirePress')
     262              ?></th><?php
     263              ?><th style='padding-right:15px;text-align:left'><?=
     264                \__('Page Template', 'domain-plugin-LoginRequirePress')
     265              ?></th><?php
     266              ?><th style='padding-right:15px;text-align:left'><?=
     267                \__('Post Status', 'domain-plugin-LoginRequirePress')
     268              ?></th><?php
     269              ?><th style='padding-right:15px;text-align:left'><?=
     270                \__('Default Visibility', 'domain-plugin-LoginRequirePress')
    252271              ?></th><?php
    253272            ?></tr><?php
     
    258277                    $isLoginRequired = isLoginRequiredForPost($post);
    259278                    $strPostName = $post->post_name;
     279                    $urlPostEdit = \get_edit_post_link($idPost);
     280                    $strPostStatus = \get_post_status($idPost);
     281                    $isPrivate = ($strPostStatus == 'private');
     282                    $strVisibility = $isPrivate ? \__('Private', 'domain-plugin-LoginRequirePress')
     283                                                : \__('Public', 'domain-plugin-LoginRequirePress');
     284                    $isPasscodeProtected = ($post->post_password != null);
     285                    if ($isPasscodeProtected) {
     286                        $strVisibility = \__('Password protected');
     287                    }
     288
     289                    if ($isPrivate) {
     290                        \array_push($arrPrivate, $post);
     291                    } else if ($isLoginRequired) {
     292                        \array_push($arrNonPrivateLoginProtected, $post);
     293                    }
     294                    if ($isPasscodeProtected) {
     295                        \array_push($arrPasscodeProtected, $post);
     296                    }
    260297                ?><input type='hidden' name='post_<?=$idPost?>'><?php
    261298                ?><tr <?=$indexRow % 2 == 0
     
    268305                    <?php
    269306                        if ($isLoginRequired) {
    270                             echo YES;
     307                            ?><font color='red'><?php
     308                              ?><?=\__(YES,'domain-plugin-LoginRequirePress')?><?php
     309                            ?></font><?php
    271310                        }
    272311                    ?>
    273312                    </td>
    274                     <td><a href='<?=get_edit_post_link($idPost)?>'><?=$idPost?></a></td>
    275                     <td><a href='<?=get_edit_post_link($idPost)?>'><?=$strPostName?></a></td>
     313                    <td><a href='<?=$urlPostEdit?>'><?=$idPost?></a></td>
     314                    <td><a href='<?=$urlPostEdit?>'><?=$strPostName?></a></td>
    276315                    <td><?=$post->post_type?></td>
    277                     <td><?=get_page_template_slug($idPost)?></td>
    278                     <td><?=get_post_status($idPost)?></td>
     316                    <td><?=\get_page_template_slug($idPost)?></td>
     317                    <td style='<?=$isPrivate ? 'color:red' : "" ?>'>
     318                      <?=$strPostStatus?>
     319                    </td>
     320                    <td style='<?=$isPrivate || $isPasscodeProtected ? 'color:red' : "" ?>'>
     321                      <?=$strVisibility?>
     322                    </td>
    279323                  </tr><?php
    280324                    $indexRow++;
    281325                }
    282                 wp_reset_postdata();
     326                \wp_reset_postdata();
    283327          ?></table><?php
    284           ?><hr><input type='submit' value='<?=__('Update LR Settings',
    285                                                   'domain-plugin-LoginRequirePress')
    286                                               ?>' class='button-primary'/><?php
     328          ?><hr><input type='submit' value='<?=\__('Update LR Settings',
     329                                                   'domain-plugin-LoginRequirePress')
     330                                              ?>' class='button-primary'<?php
     331                                               ?> style='margin-bottom:3em'/><?php
     332
     333              if (\count($arrPrivate) > 0) {
     334                  ?><hr><?php
     335                  ?><h3><?php
     336                    ?><?=\__('Private post(s):',
     337                             'domain-plugin-LoginRequirePress')?><?php
     338                  ?></h3><?php
     339                  ?><i><?php
     340                    ?><?=\__('These posts are invisible to the public, as well as to the logged-in Subscribers, Contributors, and other Authors.  Post visibility can be edited on each post\'s edit page.',
     341                             'domain-plugin-LoginRequirePress')?><?php
     342                  ?></i><?php
     343                  ?><ul><?php
     344                  foreach ($arrPrivate as $postPrivate) {
     345                      ?><li><?php
     346                        ?><a href='<?=\get_edit_post_link($postPrivate->ID)?>'><?php
     347                          ?><?=$postPrivate->post_name?><?php
     348                        ?></a><?php
     349                      ?></li><?php
     350                  }
     351                  ?></ul><?php
     352              }
     353
     354              if (\count($arrNonPrivateLoginProtected) > 0) {
     355                  ?><hr><?php
     356                  ?><h3><?php
     357                    ?><?=\__('Non-private login-protected post(s):',
     358                             'domain-plugin-LoginRequirePress')?><?php
     359                  ?></h3><?php
     360                  ?><i><?php
     361                    ?><?=\__('These posts will require user login to see, but all logged-in users will be able to see them, hence they\'re not "private".  The login protection can be modified in the table above.',
     362                             'domain-plugin-LoginRequirePress')?><?php
     363                  ?></i><?php
     364                  ?><ul><?php
     365                  foreach ($arrNonPrivateLoginProtected as $postLoginProtected) {
     366                      ?><li><?php
     367                        ?><a href='<?=\get_edit_post_link($postLoginProtected->ID)?>'><?php
     368                          ?><?=$postLoginProtected->post_name?><?php
     369                        ?></a><?php
     370                      ?></li><?php
     371                  }
     372                  ?></ul><?php
     373              }
     374
     375              if (\count($arrPasscodeProtected) > 0) {
     376                  ?><hr><?php
     377                  ?><h3><?php
     378                    ?><?=\__('Passcode-protected post(s):',
     379                             'domain-plugin-LoginRequirePress')?><?php
     380                  ?></h3><?php
     381                  ?><i><?php
     382                    ?><?=\__('Also known as the WordPress "Password Protected" posts, but different from login-protected.  The content of any of these posts will be invisible to the public, as well as to any logged-in users, until they enter a special post-only passcode / password, previously chosen in the Post Visibility section of each of these posts\' edit pages.  Any post that is both login protected and "Password Protected" will require user login, and then the entry of the additional post-only passcode to see its content.',
     383                             'domain-plugin-LoginRequirePress')?><?php
     384                  ?></i><?php
     385                  ?><ul><?php
     386                  foreach ($arrPasscodeProtected as $postPasscodeProtected) {
     387                      ?><li><?php
     388                        ?><a href='<?=\get_edit_post_link($postPasscodeProtected->ID)?>'><?php
     389                          ?><?=$postPasscodeProtected->post_name?><?php
     390                        ?></a><?php
     391                      ?></li><?php
     392                  }
     393                  ?></ul><?php
     394              }
    287395          } else {
    288           ?><?=__('No posts', 'domain-plugin-LoginRequirePress')?><?php
     396          ?><?=\__('No posts', 'domain-plugin-LoginRequirePress')?><?php
    289397          }
    290398      ?></form></div><?php
  • loginrequirepress/trunk/readme.txt

    r1202010 r1397531  
    33Tags: require login, password protect, security, limit access, control access, members, visitors, subscribers
    44Requires at least: 3.8.1
    5 Tested up to: 4.2.2
    6 Stable tag: 0.1.2
     5Tested up to: 4.5
     6Stable tag: 1.0.0
    77License: GPLv3
    88License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    1414Overview:
    1515
    16   At the time of this writing, the latest version of WordPress, version 4.2.2,
     16  At the time of this writing, the latest version of WordPress, version 4.5,
    1717  has 3 post visibility options, which are 'public', 'password protected', and
    1818  'private'.
     
    5353  page listings.
    5454
     55  Login-requiring posts are marked with a custom field 'login_require_press' set to 'yes'.
     56
    5557Official project URLs:
    5658
     
    6668== Frequently Asked Questions ==
    6769
     70= What do I do if I get this error "Plugin could not be activated because it triggered a fatal error." when trying to activate? =
     71
     72Upgrade to PHP >= 5.4  See
     73https://wordpress.org/support/topic/crashes-on-activate
     74
     75Make sure to check your PHP version with
     76https://wordpress.org/plugins/display-php-version/
     77
    6878= Where can I ask a question about LoginRequirePress? =
    6979
     
    7484Post issues / bugs / feature requests at: https://github.com/maratbn/LoginRequirePress/issues
    7585
     86= Plugin is missing feature X that I really want, what do I do? =
     87
     88Post a bug / feature request, or implement the feature at your leisure, and submit a pull request.
     89
    7690== Screenshots ==
    7791
    78 1. LoginRequirePress configuration screen.
     921. LoginRequirePress configuration screen with the table used to specify which posts are to be
     93   login-protected.
     94
     952. LoginRequirePress configuration screen with the lists of private, non-private login-protected,
     96   and passcode-protected posts.
    7997
    8098== Changelog ==
    8199
    82 = 0.1.0 =
    83 * Initial release.
    84 
    85 = 0.1.1 =
    86 * Various documentation improvement.
     100= 1.0.0 =
     101* Version incremented to 1.0.0 to signify public release.
     102* Tested up to WordPress 4.5
     103* Login Required status indicators now in red.
     104* Added new 'Default Visibility' column, that indicates posts' present visibility according to the
     105  default WordPress logic without this plugin.
     106* Explicitly listing-out the Private, Login-Protected, and Passcode/Password-Protected posts.
     107* Added plugin activation check for PHP version >= 5.4
     108* Revised screenshot 1 to display the latest UI, and added screenshot 2.
    87109
    88110= 0.1.2 =
     
    91113* Fixed issue https://github.com/maratbn/LoginRequirePress/issues/3:  Protecting the titles and
    92114  contents of login-requiring posts in search result page listings when the user is not logged in.
     115
     116= 0.1.1 =
     117* Various documentation improvement.
     118
     119= 0.1.0 =
     120* Initial release.
Note: See TracChangeset for help on using the changeset viewer.