Skip to content

Commit

Permalink
added ACF 4.x support
Browse files Browse the repository at this point in the history
bumped version 1.1.0
  • Loading branch information
solepixel committed Nov 12, 2016
1 parent 958acfc commit c73ff4c
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 94 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# WP Multiple Passwords
Allow multiple passwords for password protected pages and posts. Includes Advanced Custom Fields (5.x) support, but not required.
Allow multiple passwords for password protected pages and posts. Includes Advanced Custom Fields (4.x, 5.x) support, but not required.

## Installation
1. Upload wp-multiple-passwords into your WordPress plugins folder.
2. Activate the plugin on the WordPress Admin Plugins page.

## Usage
1. Create a post or page and set visibility to Password Protected
2. Set your password
3. Save/Update your post/page
4. If using ACF (5.x) you will see a new meta box titled "Additional Passwords"
4. If using ACF (4.x, 5.x) you will see a new meta box titled "Additional Passwords"
5. Enter as many passwords as you'd like to allow access to this page.
6. Update your post/page.

If you are using ACF (Advanced Custom Fields) 5.x, there's nothing left to do. If you would like to use your own meta box solution, follow the instructions below to hook into this plugin. Advanced Custom Fields 4.x is currently not supported.
If you are using ACF (Advanced Custom Fields) 4.x or 5.x, there's nothing left to do. If you would like to use your own meta box solution, follow the instructions below to hook into this plugin. Advanced Custom Fields 4.x is currently not supported.

## Custom Meta Box
You may choose not to use ACF to handle your additional password storage and would like to build your own, or maybe you just want to hard code some extra passwords into your theme. The plugin has a filter for passing passwords into a post/page.
Expand All @@ -32,7 +32,7 @@ function mytheme_extra_string_passwords( $extra_passwords, $post ){
);
$extra_passwords = array_merge( $extra_passwords, $new_passwords );
return $extra_passwords;
}
```
Expand All @@ -56,9 +56,9 @@ function mytheme_extra_array_passwords( $extra_passwords, $post ){
'usage' => 'For legacy support of the old password.'
)
);
$extra_passwords = array_merge( $extra_passwords, $new_passwords );
return $extra_passwords;
}
```
Expand All @@ -68,6 +68,9 @@ It is required by this plugin to have an actual password stored in the original

## Changelog

#### 1.1.0
* Added support for ACF 4.x (Free, non-PRO version)

#### 1.0.1
* Added some checks for proper syntax
* Trimmed whitespace from passwords
Expand Down
218 changes: 131 additions & 87 deletions multiple-passwords.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: WP Multiple Passwords
Plugin URI: https://github.com/solepixel/wp-multiple-passwords
Description: Store Multiple Passwords for Password protected posts and pages. Includes Advanced Custom Fields support, but can work with any setup by using the filter <code>wpmp_extra_passwords</code>.
Version: 1.0.1
Version: 1.1.0
Author: Brian DiChiara
Author URI: http://briandichiara.com
Text Domain: wpmp
Expand Down Expand Up @@ -44,10 +44,15 @@ function wpmp_override_password(){

// this part needs ACF
$extra_passwords = function_exists( 'get_field' ) ? get_field( '_extra_passwords' ) : array();


// this will add non-pro ACF support
if( $extra_passwords && ! function_exists('acf_add_local_field_group') && function_exists('register_field_group') ){
$extra_passwords = array_filter( preg_split( '/\r\n|[\r\n]/', $extra_passwords ) );
}

// You can set your own passwords here: (see below)
$extra_passwords = apply_filters( 'wpmp_extra_passwords', $extra_passwords, $post );

/*
# $extra_passwords format needs to be passed as an array in plain text:
Expand Down Expand Up @@ -94,7 +99,7 @@ function wpmp_override_password(){

if( is_array( $check_password ) && isset( $check_password['password'] ) ) // ACF Support
$check_password = $check_password['password'];

if( is_string( $check_password ) || is_numeric( $check_password ) )
$check_password = trim( $check_password );
else
Expand Down Expand Up @@ -185,94 +190,133 @@ function wpmp_location_rules_match_visibility( $match, $rule, $options ){
return $match;
}


if( function_exists('acf_add_local_field_group') ):

acf_add_local_field_group(array (
'key' => 'group_579786b845c7f',
'title' => __( 'Additional Passwords', 'wpmp' ),
'fields' => array (
$wpmp_repeater_field = array (
'key' => 'field_579786e0d0eea',
'label' => __( 'Extra Passwords', 'wpmp' ),
'name' => '_extra_passwords',
'type' => 'repeater',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'collapsed' => 'field_57978711d0eec',
'min' => '',
'max' => '',
'layout' => 'block',
'button_label' => __( 'Add Password', 'wpmp' ),
'sub_fields' => array (
array (
'key' => 'field_579786fcd0eeb',
'label' => __( 'Password', 'wpmp' ),
'name' => 'password',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
),
array (
'key' => 'field_57978711d0eec',
'label' => __( 'Label', 'wpmp' ),
'name' => 'label',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
),
),
);

$wpmp_textarea_field = array (
'key' => 'field_582771dd32cb8',
'label' => __( 'Extra Passwords', 'wpmp' ),
'name' => '_extra_passwords',
'type' => 'textarea',
'instructions' => __( 'Place passwords on individual lines.', 'wpmp' ),
'default_value' => '',
'placeholder' => '',
'maxlength' => '',
'rows' => 6,
'formatting' => 'none',
);

$addl_passwords_field = array (
'key' => 'group_579786b845c7f',
'title' => __( 'Additional Passwords', 'wpmp' ),
'options' => array (
'position' => 'side',
'layout' => 'default',
'hide_on_screen' => array (
),
),
'fields' => array (),
'location' => array (
array (
array (
'key' => 'field_579786e0d0eea',
'label' => __( 'Extra Passwords', 'wpmp' ),
'name' => '_extra_passwords',
'type' => 'repeater',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'collapsed' => 'field_57978711d0eec',
'min' => '',
'max' => '',
'layout' => 'block',
'button_label' => __( 'Add Password', 'wpmp' ),
'sub_fields' => array (
array (
'key' => 'field_579786fcd0eeb',
'label' => __( 'Password', 'wpmp' ),
'name' => 'password',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
),
array (
'key' => 'field_57978711d0eec',
'label' => __( 'Label', 'wpmp' ),
'name' => 'label',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
),
),
'param' => 'page_visibility',
'operator' => '==',
'value' => 'password',
'order_no' => 0,
'group_no' => 0,
),
),
'location' => array (
array (
array (
array (
'param' => 'post_visibility',
'operator' => '==',
'value' => 'password',
),
'param' => 'post_visibility',
'operator' => '==',
'value' => 'password',
'order_no' => 0,
'group_no' => 1,
),
),
'menu_order' => 0,
'position' => 'side',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
));
),
'menu_order' => 0,
'position' => 'side',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
);

if( function_exists('acf_add_local_field_group') ):

$addl_passwords_field['fields'] = array( $wpmp_repeater_field );

acf_add_local_field_group( $addl_passwords_field );

elseif( function_exists('register_field_group') ):

$addl_passwords_field['fields'] = array( $wpmp_textarea_field );

register_field_group( $addl_passwords_field );

endif;

0 comments on commit c73ff4c

Please sign in to comment.