Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,174 @@
<?php
/**
* Easy Digital Downloads Integration
*
* @package Restrict Content Pro
* @subpackage Integrations/EDD
* @copyright Copyright (c) 2017, Restrict Content Pro
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 2.7
*/
class RCP_EDD {
/**
* @var WP_User
*/
private $user;
/**
* @var RCP_Member
* @deprecated 3.0
*/
private $member;
/**
* RCP_EDD constructor.
*
* @return void
*/
public function __construct() {
$this->user = wp_get_current_user();
add_filter( 'edd_can_purchase_download', array( $this, 'can_purchase' ), 10, 2 );
add_filter( 'edd_purchase_download_form', array( $this, 'download_form' ), 10, 2 );
add_filter( 'edd_file_download_has_access', array( $this, 'file_download_has_access' ), 10, 3 );
add_filter( 'edd_downloads_query', array( $this, 'edd_downloads_query' ), 10, 2 );
add_filter( 'edd_downloads_excerpt', array( $this, 'edd_downloads_excerpt' ) );
}
/**
* Restricts the ability to purchase a product if the user doesn't have access to it.
*
* @param bool $can_purchase
* @param EDD_Download $download
*
* @access public
* @since 2.7
* @return bool
*/
public function can_purchase( $can_purchase, $download ) {
if ( ! $can_purchase || ! rcp_user_can_access( $this->user->ID, $download->ID ) ) {
$can_purchase = false;
}
return $can_purchase;
}
/**
* Overrides the purchase form if the user doesn't have access to the product.
*
* @param string $purchase_form Purchase form HTML.
* @param array $args Array of arguments for display.
*
* @access public
* @since 2.7
* @return string
*/
public function download_form( $purchase_form, $args ) {
if ( ! rcp_user_can_access( $this->user->ID, $args['download_id'] ) ) {
return '';
}
return $purchase_form;
}
/**
* Prevents downloading files if the member doesn't have access.
*
* @param bool $has_access Whether or not the member has access.
* @param int $payment_id ID of the payment to check.
* @param array $args Array of arguments.
*
* @access public
* @since 2.7
* @return bool
*/
public function file_download_has_access( $has_access, $payment_id, $args ) {
if ( ! rcp_user_can_access( $this->user->ID, $args['download'] ) ) {
$has_access = false;
}
return $has_access;
}
/**
* Removes restricted downloads from the [downloads] shortcode query.
*
* @param array $query Query arguments.
* @param array $atts Shortcode attributes.
*
* @access public
* @since 2.7
* @return array
*/
public function edd_downloads_query( $query, $atts ) {
global $rcp_options;
if ( ! isset( $rcp_options['hide_premium'] ) ) {
return $query;
}
$customer = rcp_get_customer(); // current customer
if ( empty( $customer ) || ! $customer->has_active_membership() ) {
$premium_ids = rcp_get_restricted_post_ids();
$term_restricted_post_ids = rcp_get_post_ids_assigned_to_restricted_terms();
$post_ids = array_unique( array_merge( $premium_ids, $term_restricted_post_ids ) );
if ( ! empty( $post_ids ) ) {
$query['post__not_in'] = $post_ids;
}
}
return $query;
}
/**
* Filters the excerpt in the [downloads] shortcode if the member doesn't have access.
*
* @param string $excerpt
*
* @access public
* @since 2.7
* @return string
*/
public function edd_downloads_excerpt( $excerpt ) {
global $rcp_options;
$post_id = get_the_ID();
$content_excerpts = isset( $rcp_options['content_excerpts'] ) ? $rcp_options['content_excerpts'] : 'individual';
/*
* Return excerpt if:
*
* - User can access the post; or:
* - Content excerpts are set to "always"; or:
* - Content excerpts are set to "individual" and this download has excerpts enabled.
*/
if ( rcp_user_can_access( $this->user->ID, $post_id ) || 'always' == $content_excerpts || ( 'individual' == $content_excerpts && get_post_meta( $post_id, 'rcp_show_excerpt', true ) ) ) {
return $excerpt;
}
return rcp_get_restricted_content_message();
}
}
/**
* Initialize the EDD integration if the plugin is activated.
*
* @since 2.7
* @return void
*/
function rcp_edd_init() {
if ( ! class_exists( 'Easy_Digital_Downloads' ) ) {
return;
}
new RCP_EDD;
}
add_action( 'init', 'rcp_edd_init' );

View File

@@ -0,0 +1,90 @@
<?php
/**
* Define the Freemius Integrations
*
* @since 3.5.23
*/
class RcpFreemius {
public function __construct() {
$this->setup();
}
// Create a helper function for easy SDK access.
public function setup()
{
global $rcp_freemius;
if (!isset($rcp_freemius)) {
// Include Freemius SDK.
require_once RCP_PLUGIN_DIR . 'core/integrations/freemius/start.php';
$rcp_freemius = fs_dynamic_init(array(
'id' => '10401',
'slug' => 'rcp',
'type' => 'plugin',
'public_key' => 'pk_b2fbc7855865cb002c41403a3efaa',
'is_premium' => false,
'has_addons' => false,
'has_paid_plans' => false,
'is_org_compliant' => false,
'menu' => array(
'slug' => 'rcp-members',
'first-path' => 'admin.php?page=restrict-content-welcome',
'account' => false,
'contact' => false,
'support' => false,
),
));
}
$rcp_freemius->add_action( 'connect_message', [ $this, 'filter_connect_message_on_update',], 10, 6 );
$rcp_freemius->add_action( 'connect_message_on_update', [ $this, 'filter_connect_message_on_update',], 10, 6 );
return $rcp_freemius;
}
public function initialize(){
// Signal that SDK was initiated.
do_action( 'rcp_freemius_loaded' );
}
public function filter_connect_message_on_update(
$message, $user_first_name, $product_title, $user_login, $site_link, $freemius_link) {
wp_enqueue_style('rcp-freemius', RCP_WEB_ROOT . 'core/includes/css/freemius.css');
// Add the heading HTML.
$plugin_name = 'Restrict Content';
$title = '<h3>' . sprintf( esc_html__( 'We hope you love %1$s', 'rcp' ), $plugin_name ) . '</h3>';
$html = '';
// Add the introduction HTML.
$html .= '<p>';
$html .= sprintf( esc_html__( 'Hi, %1$s! This is an invitation to help our %2$s community. If you opt-in, some data about your usage of %2$s will be shared with our teams (so they can work their butts off to improve). We will also share some helpful info on membership site management, WordPress, and our products from time to time.', 'rcp' ), $user_first_name, $plugin_name );
$html .= '</p>';
$html .= '<p>';
$html .= sprintf( esc_html__( 'And if you skip this, that\'s okay! %1$s will still work just fine.', 'rcp' ), $plugin_name );
$html .= '</p>';
// Add the "Powered by" HTML.
$html .= '<div class="tribe-powered-by-freemius">' . esc_html__( 'Powered by', 'rcp' ) . '</div>';
return $title . $html;
}
/**
* Get the plugin icon URL.
*
* @since 5.0.2
*
* @return string The plugin icon URL.
*/
public function get_plugin_icon_url() {
return RCP_WEB_ROOT. 'core/includes/images/Full-Logo-1.svg';
}
}
$freemius = new RcpFreemius();
$freemius->initialize();

View File

@@ -0,0 +1,70 @@
<?php
/**
* Google Authenticator Integration
*
* @package Restrict Content Pro
* @subpackage Integrations/Google Authenticator
* @copyright Copyright (c) 2017, Restrict Content Pro
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 2.2
*/
class RCP_Google_Authenticator {
/**
* Get things started
*
* @access public
* @since 2.2
*/
public function __construct() {
if( ! class_exists( 'GoogleAuthenticator' ) ) {
return;
}
add_action( 'rcp_login_form_fields_before_submit', array( $this, 'auth_code_input' ) );
add_action( 'rcp_after_login_form_fields', array( GoogleAuthenticator::$instance, 'loginfooter' ) );
add_action( 'rcp_login_form_errors', array( $this, 'check_code' ) );
}
/**
* Add the authentication code input field
*
* @access public
* @since 2.2
*/
public function auth_code_input() {
?>
<p>
<label for="googleotp"><?php _e( 'Google Authenticator Code', 'rcp' ); ?></label>
<input type="text" name="googleotp" id="googleotp" class="rcp-input" value="" size="20" style="ime-mode: inactive;" />
</p>
<?php
}
/**
* Verify the entered code
*
* @param $post_data
*
* @access public
* @since 2.2
* @return void
*/
public function check_code( $post_data ) {
$auth = new GoogleAuthenticator;
$user = get_user_by( 'login', trim( $_POST['rcp_user_login'] ) );
$success = $auth->check_otp( $user, trim( $_POST['rcp_user_login'] ), trim( $_POST['rcp_user_pass'] ) );
if( is_wp_error( $success ) ) {
rcp_errors()->add( 'auth_failed', $success->get_error_message(), 'login' );
}
}
}
new RCP_Google_Authenticator;

View File

@@ -0,0 +1,380 @@
<?php
/**
* Define the StellarWP Telemetry Integrations
*
* @since 3.5.27
* @package RCP
*/
use RCP\StellarWP\Telemetry\Opt_In\Opt_In_Template;
use RCP\StellarWP\Telemetry\Opt_In\Status;
use RCP\StellarWP\Telemetry\Config;
/**
* Define the StellarWP Telemetry Integrations and configurations.
*
* @since 3.5.27
*/
class RCP_Telemetry {
/**
* The Container Interface.
*
* @since 3.5.27
* @var RCP\Container $container The RCP Container.
* @access protected
*/
protected $container;
/**
* The Restrict Content Instance
*
* @since 3.5.28
* @var Restrict_Content_Pro $restrict_content The RCP Instance.
* @access private
*/
private $restrict_content;
/**
* Initialize variables.
*
* @since 3.5.27
*/
public function __construct() {
$this->container = Config::get_container();
$this->restrict_content = restrict_content_pro();
}
/**
* Set up the actions and filters. We avoid adding the hooks in the constructor since it happens before some
* dependencies are declare.
*
* @since 3.5.27
* @return void
*/
public function init() {
// Add Filters.
add_filter( 'stellarwp/telemetry/restrict-content-pro/optin_args', [ $this, 'telemetry_messages' ] );
add_filter( 'stellarwp/telemetry/restrict-content-pro/exit_interview_args', [ $this, 'exit_interview' ] );
add_filter( 'stellarwp/telemetry/restrict-content/optin_args', [ $this, 'telemetry_messages' ] );
add_filter( 'stellarwp/telemetry/restrict-content/exit_interview_args', [ $this, 'exit_interview' ] );
add_filter( 'plugin_action_links', [ $this, 'add_opt_in_link' ], 10, 2 );
add_filter( 'admin_init', [ $this, 'update_opt_in_get_status' ] );
add_filter( 'admin_init', [ $this, 'check_interview_selection' ] );
add_filter( 'debug_information', [ $this, 'add_rcp_info_to_telemetry' ], 10, 1 );
}
/**
* We customize the Telemetry Labels for RCP.
*
* @since 3.5.27
* @param array $_args The Telemetry Labels.
* @return array The modified labels.
*/
public function telemetry_messages( $_args ) {
$_args['plugin_logo_width'] = '300';
$_args['plugin_logo_height'] = '50';
$_args['permissions_url'] = 'https://restrictcontentpro.com/telemetry-tracking/';
$_args['tos_url'] = 'https://restrictcontentpro.com/terms-of-service/';
$_args['privacy_url'] = 'https://stellarwp.com/privacy-policy/';
$rcp_title = 'Restrict Content Pro';
if ( $this->restrict_content->is_pro() ) {
$_args['plugin_logo'] = RCP_WEB_ROOT . 'core/includes/images/Full-Logo-1.svg';
$_args['heading'] = __( 'We hope you love Restrict Content Pro.', 'rcp' );
} else {
$_args['plugin_logo'] = RCP_WEB_ROOT . 'core/includes/images/restrict_content_logo.svg';
$_args['heading'] = __( 'We hope you love Restrict Content.', 'rcp' );
$rcp_title = 'Restrict Content';
}
if ( ! $this->check_freemius_status() ) {
$_args['intro'] = sprintf(
// translators:%1\$s: The user name.
__( "Hi, %1\$s! This is an invitation to help our %2\$s community. If you opt-in, some data about your usage of %3\$s will be shared with our teams (so they can work their butts off to improve). We will also share some helpful info on membership site management, WordPress, and our products from time to time. And if you skip this, that's okay! %4\$s will still work just fine.", 'rcp' ),
wp_get_current_user()->display_name,
$rcp_title,
$rcp_title,
$rcp_title
);
} else {
$_args['intro'] = sprintf(
// translators: %s: The user name.
__( "Hello, %s! We just wanted to let you know that we've replaced Freemius with our own Telemetry feature. This new Telemetry removes the middle man (Freemius) and as a result is much more privacy-friendly. Rather than sending helpful information to Freemius, who then sends it to us, the information is now sent directly to us. Click 'Allow & Continue' to continue sharing this helpful information using our new Telemetry feature.", 'rcp' ),
wp_get_current_user()->display_name
);
}
return $_args;
}
/**
* Add Opt-In links to plugin actions.
*
* @param array $plugin_actions The Plugin Actions for each plugin.
* @param string $plugin_file The main plugin file name.
* @since 1.0
* @return array The additional plugin actions.
*/
public function add_opt_in_link( $plugin_actions, $plugin_file ) {
$new_actions = array();
$opt_in_status = $this->container->get( Status::class )->is_active();
if ( ( $opt_in_status && ( basename( RCP_ROOT ) . '/restrict-content-pro.php' === $plugin_file ) )
|| ( $opt_in_status && ( basename( RCP_ROOT ) . '/restrictcontent.php' === $plugin_file ) ) ) {
$new_actions['rcp_opt_out'] = sprintf(
// translators: %s: The admin URL.
__( '<a href="%1$s" alt="%2$s">Opt-Out</a>', 'rcp' ),
// translators: %s: The Opt-Out alt text.
esc_url( admin_url( 'plugins.php?opt-in-status=0' ) ),
__( 'Change to Opt Out Status', 'rcp' )
);
} elseif ( ( ! $opt_in_status && ( basename( RCP_ROOT ) . '/restrict-content-pro.php' === $plugin_file ) )
|| ( ! $opt_in_status && ( basename( RCP_ROOT ) . '/restrictcontent.php' === $plugin_file ) ) ) {
$new_actions['rcp_opt_in'] = sprintf(
// translators: %s: The admin URL.
__( '<a href="%1$s" alt="%2$s">Opt-In</a>', 'rcp' ),
esc_url( admin_url( 'plugins.php?opt-in-status=1' ) ),
// translators: %s: The Opt-Out alt text.
__( 'Change to Opt In Status', 'rcp' )
);
}
return array_merge( $new_actions, $plugin_actions );
}
/**
* Update the Opt-In status. This captures the link that was trigger in the Plugins Actions Page.
*
* @since 3.5.27
* @return void
*/
public function update_opt_in_get_status() {
// Bail early if we're not saving the Opt-In Status field.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( ! isset( $_GET['opt-in-status'] ) ) {
return;
}
$value = (int) filter_input( INPUT_GET, 'opt-in-status' );
// Get the slug configured.
$stellar_slug = Config::get_stellar_slug();
if ( $value ) {
// Set Telemetry modal to be visible if the user decides to Opt In.
update_option( $this->container->get( Opt_In_Template::class )->get_option_name( $stellar_slug ), '1' );
$redirect = add_query_arg( 'rcp_message', '', esc_url( admin_url( 'admin.php?page=rcp-settings' ) ) );
} else {
$this->container->get( Status::class )->set_status( $value );
$redirect = add_query_arg( 'rcp_message', 'opt_out_message', esc_url( admin_url( 'admin.php?page=rcp-settings' ) ) );
}
wp_safe_redirect( $redirect );
exit;
}
/**
* Sets the logo and labels for the exit interview.
*
* @since 3.5.27
* @param array $_args The exit interview labels.
* @return array The custom labels.
*/
public function exit_interview( $_args ) {
$_args['plugin_logo_width'] = '300';
$_args['plugin_logo_height'] = '50';
if ( $this->restrict_content->is_pro() ) {
$_args['plugin_logo'] = RCP_WEB_ROOT . 'core/includes/images/Full-Logo-1.svg';
$_args['plugin_logo_alt'] = 'Restrict Content Pro Logo';
} else {
$_args['plugin_logo'] = RCP_WEB_ROOT . 'core/includes/images/restrict_content_logo.svg';
$_args['plugin_logo_alt'] = 'Restrict Content Logo';
}
return $_args;
}
/**
*
* Check for specific freemius valules related to RCP and delete them, the updates the Freemius options.
*
* @return bool True if settings got deleted.
*/
private function wipe_rcp_freemius() {
$fs_accounts = get_option( 'fs_accounts' );
if ( isset( $fs_accounts['id_slug_type_path_map']['10401'] ) ) {
unset( $fs_accounts['id_slug_type_path_map']['10401'] );
} else {
return false;
}
if ( isset( $fs_accounts['plugin_data']['rcp'] ) ) {
unset( $fs_accounts['plugin_data']['rcp'] );
}
if ( isset( $fs_accounts['file_slug_map']['restrict-content-pro/restrict-content-pro.php'] ) ) {
unset( $fs_accounts['file_slug_map']['restrict-content-pro/restrict-content-pro.php'] );
}
if ( isset( $fs_accounts['file_slug_map']['restrict-content/restrictcontent.php'] ) ) {
unset( $fs_accounts['file_slug_map']['restrict-content/restrictcontent.php'] );
}
if ( isset( $fs_accounts['plugins']['rcp'] ) ) {
unset( $fs_accounts['plugins']['rcp'] );
}
if ( isset( $fs_accounts['plans']['rcp'] ) ) {
unset( $fs_accounts['plans']['rcp'] );
}
if ( isset( $fs_accounts['sites']['rcp'] ) ) {
unset( $fs_accounts['sites']['rcp'] );
}
update_option( 'fs_accounts', $fs_accounts );
return true;
}
/**
* Checks if Freemius is active for RCP.
*
* @return bool True if freemius was activated for RCP.
*/
private function check_freemius_status() {
$fs_accounts = get_option( 'fs_accounts' );
if ( isset( $fs_accounts['plugin_data']['rcp'] ) ) {
if ( isset( $fs_accounts['plugin_data']['rcp']['activation_timestamp'] ) ) {
return true;
} else {
return false;
}
}
return false;
}
/**
* Check if the user opt-in so that we can wipe the Freemius RCP data.
*
* @return void
*/
public function check_interview_selection() {
// We're not attempting an action.
if ( empty( $_POST['_wpnonce'] ) ) {
return;
}
$nonce = sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) );
if ( ! wp_verify_nonce( $nonce, 'stellarwp-telemetry' ) ) {
return;
}
// We're not attempting a telemetry action.
if ( isset( $_POST['action'] ) && 'stellarwp-telemetry' !== $_POST['action'] ) {
return;
}
// The user did not respond to the opt-in modal.
if ( ! isset( $_POST['optin-agreed'] ) ) {
return;
}
// User agreed to opt-in to Telemetry.
if ( 'true' === $_POST['optin-agreed'] ) {
$fs_status = $this->check_freemius_status();
if ( $fs_status ) {
$this->wipe_rcp_freemius();
}
}
}
/**
* Fill information that is sent to Telemetry for analysis purposes.
*
* @param array $_info Information if exists.
* @return array the Filtered array.
*/
public function add_rcp_info_to_telemetry( array $_info ) : array {
$telemetry_info = new RCP_Telemetry_Info();
$rcp_title = 'Restrict Content Pro';
$rcp_slug = 'restrict-content-pro';
$restrict_content_version = ! $this->restrict_content->is_pro() ? RCF_VERSION : RCP_PLUGIN_VERSION;
if ( ! $this->restrict_content->is_pro() ) {
$rcp_title = 'Restrict Content';
$rcp_slug = 'restrict-content';
}
$_info[ $rcp_slug ] = [
'label' => $rcp_title,
// translators: %s: The RCP Title.
'description' => sprintf( esc_html__( 'These are %s fields that we use for analysis and to make the product better.', 'rcp' ), $rcp_title ),
'fields' => [
[
'label' => esc_html__( 'Version', 'rcp' ),
'value' => $restrict_content_version,
],
[
'label' => esc_html__( 'Last Updated', 'rcp' ),
'value' => $telemetry_info->rcp_last_updated(),
],
[
'label' => esc_html__( 'Total Membership Levels', 'rcp' ),
'value' => $telemetry_info->total_membership_levels(),
],
[
'label' => esc_html__( 'Total Paid Membership Levels', 'rcp' ),
'value' => $telemetry_info->total_paid_membership_levels(),
],
[
'label' => esc_html__( 'Total Free Membership Levels', 'rcp' ),
'value' => $telemetry_info->total_free_membership_levels(),
],
[
'label' => esc_html__( 'Total One-Time Membership Levels', 'rcp' ),
'value' => $telemetry_info->total_one_time_membership_levels(),
],
[
'label' => esc_html__( 'Total Recurring Membership Levels', 'rcp' ),
'value' => $telemetry_info->total_recurring_membership_levels(),
],
[
'label' => esc_html__( 'Total Paying Customers', 'rcp' ),
'value' => $telemetry_info->total_paying_customers(),
],
[
'label' => esc_html__( 'Total Free Customers', 'rcp' ),
'value' => $telemetry_info->total_free_customers(),
],
[
'label' => esc_html__( 'Total No-Membership Customers', 'rcp' ),
'value' => $telemetry_info->total_no_membership_customers(),
],
[
'label' => esc_html__( 'Is Multiple Memberships', 'rcp' ),
'value' => $telemetry_info->is_multiple_memberships(),
],
[
'label' => esc_html__( 'Total Revenue This Month', 'rcp' ),
'value' => $telemetry_info->monthly_revenue(),
],
[
'label' => esc_html__( 'Payment Gateways', 'rcp' ),
'value' => wp_json_encode( $telemetry_info->payment_gateways() ),
],
[
'label' => esc_html__( 'Active Add-ons', 'rcp' ),
'value' => wp_json_encode( $telemetry_info->active_addons() ),
],
[
'label' => esc_html__( 'Deactivated Add-ons', 'rcp' ),
'value' => wp_json_encode( $telemetry_info->deactivated_addons() ),
],
],
];
return $_info;
}
}

View File

@@ -0,0 +1,426 @@
<?php
/**
* WooCommerce Integration
*
* @package Restrict Content Pro
* @subpackage Integrations/WooCommerce
* @copyright Copyright (c) 2017, Restrict Content Pro
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 2.2
*/
class RCP_WooCommerce {
/**
* Get things started
*
* @access public
* @since 2.2
*/
public function __construct() {
if( ! class_exists( 'WooCommerce' ) ) {
return;
}
add_filter( 'woocommerce_product_data_tabs', array( $this, 'data_tab' ) );
add_action( 'woocommerce_product_data_panels', array( $this, 'data_display' ) );
add_action( 'save_post_product', array( $this, 'save_meta' ) );
add_filter( 'woocommerce_is_purchasable', array( $this, 'is_purchasable' ), 999999, 2 );
add_filter( 'woocommerce_product_is_visible', array( $this, 'is_visible' ), 999999, 2 );
add_filter( 'wc_get_template_part', array( $this, 'hide_template' ), 999999, 3 );
}
/**
* Register the product settings tab
*
* @param array $tabs
*
* @access public
* @since 2.2
* @return array
*/
public function data_tab( $tabs ) {
$tabs['access'] = array(
'label' => __( 'Access Control', 'rcp' ),
'target' => 'rcp_access_control',
'class' => array(),
);
return $tabs;
}
/**
* Display product settings
*
* @access public
* @since 2.2
* @return void
*/
public function data_display() {
?>
<div id="rcp_access_control" class="panel woocommerce_options_panel">
<div class="options_group">
<p><?php _e( 'Restrict purchasing of this product to:', 'rcp' ); ?></p>
<?php
woocommerce_wp_checkbox( array(
'id' => '_rcp_woo_active_to_purchase',
'label' => __( 'Active subscribers only?', 'rcp' ),
'cbvalue' => 1
) );
$levels = (array) get_post_meta( get_the_ID(), '_rcp_woo_subscription_levels_to_purchase', true );
foreach ( rcp_get_membership_levels( array( 'number' => 999 ) ) as $level ) {
woocommerce_wp_checkbox( array(
'name' => '_rcp_woo_subscription_levels_to_purchase[]',
'id' => '_rcp_woo_subscription_level_' . $level->get_id(),
'label' => $level->get_name(),
'value' => in_array( $level->get_id(), $levels ) ? $level->get_id() : 0,
'cbvalue' => $level->get_id()
) );
}
woocommerce_wp_select( array(
'id' => '_rcp_woo_access_level_to_purchase',
'label' => __( 'Access level required?', 'rcp' ),
'options' => rcp_get_access_levels()
) );
?>
</div>
<div class="options_group">
<p><?php _e( 'Restrict viewing of this product to:', 'rcp' ); ?></p>
<?php
woocommerce_wp_checkbox( array(
'id' => '_rcp_woo_active_to_view',
'label' => __( 'Active subscribers only?', 'rcp' ),
'cbvalue' => 1
) );
$levels = (array) get_post_meta( get_the_ID(), '_rcp_woo_subscription_levels_to_view', true );
foreach ( rcp_get_membership_levels( array( 'number' => 999 ) ) as $level ) {
woocommerce_wp_checkbox( array(
'name' => '_rcp_woo_subscription_levels_to_view[]',
'id' => '_rcp_woo_subscription_level_to_view_' . $level->get_id(),
'label' => $level->get_name(),
'value' => in_array( $level->get_id(), $levels ) ? $level->get_id() : 0,
'cbvalue' => $level->get_id()
) );
}
woocommerce_wp_select( array(
'id' => '_rcp_woo_access_level_to_view',
'label' => __( 'Access level required?', 'rcp' ),
'options' => rcp_get_access_levels()
) );
?>
</div>
<input type="hidden" name="rcp_woocommerce_product_meta_box_nonce" value="<?php echo wp_create_nonce( 'rcp_woocommerce_product_meta_box_nonce' ); ?>" />
</div>
<?php
}
/**
* Saves product access settings
*
* @param int $post_id ID of the post being saved.
*
* @access public
* @since 2.2
* @return int|void
*/
public function save_meta( $post_id = 0 ) {
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
if ( ! isset( $_POST['rcp_woocommerce_product_meta_box_nonce'] ) || ! wp_verify_nonce( $_POST['rcp_woocommerce_product_meta_box_nonce'], 'rcp_woocommerce_product_meta_box_nonce' ) ) {
return;
}
// Don't save revisions and autosaves
if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
return $post_id;
}
// Check user permission
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
if( isset( $_POST['_rcp_woo_active_to_purchase'] ) ) {
update_post_meta( $post_id, '_rcp_woo_active_to_purchase', 1 );
} else {
delete_post_meta( $post_id, '_rcp_woo_active_to_purchase' );
}
if( isset( $_POST['_rcp_woo_access_level_to_purchase'] ) ) {
update_post_meta( $post_id, '_rcp_woo_access_level_to_purchase', sanitize_text_field( $_POST['_rcp_woo_access_level_to_purchase'] ) );
} else {
delete_post_meta( $post_id, '_rcp_woo_access_level_to_purchase' );
}
if( isset( $_POST['_rcp_woo_subscription_levels_to_purchase'] ) ) {
update_post_meta( $post_id, '_rcp_woo_subscription_levels_to_purchase', array_map( 'absint', $_POST['_rcp_woo_subscription_levels_to_purchase'] ) );
} else {
delete_post_meta( $post_id, '_rcp_woo_subscription_levels_to_purchase' );
}
if( isset( $_POST['_rcp_woo_active_to_view'] ) ) {
update_post_meta( $post_id, '_rcp_woo_active_to_view', 1 );
} else {
delete_post_meta( $post_id, '_rcp_woo_active_to_view' );
}
if( isset( $_POST['_rcp_woo_access_level_to_view'] ) ) {
update_post_meta( $post_id, '_rcp_woo_access_level_to_view', sanitize_text_field( $_POST['_rcp_woo_access_level_to_view'] ) );
} else {
delete_post_meta( $post_id, '_rcp_woo_access_level_to_view' );
}
if( isset( $_POST['_rcp_woo_subscription_levels_to_view'] ) ) {
update_post_meta( $post_id, '_rcp_woo_subscription_levels_to_view', array_map( 'absint', $_POST['_rcp_woo_subscription_levels_to_view'] ) );
} else {
delete_post_meta( $post_id, '_rcp_woo_subscription_levels_to_view' );
}
}
/**
* Restrict the ability to purchase a product
*
* @param bool $ret
* @param WC_Product $product
*
* @access public
* @since 2.2
* @return bool
*/
public function is_purchasable( $ret, $product ) {
if ( ! $ret ) {
return $ret;
}
return rcp_user_can_purchase_woocommerce_product( get_current_user_id(), $product->get_id() );
}
/**
* Restrict the visibility of a product
*
* @param bool $ret
* @param int $product_id
*
* @access public
* @since 2.2
* @return bool
*/
public function is_visible( $ret, $product_id ) {
if( ! $ret ) {
return $ret;
}
if ( current_user_can( 'edit_post', $product_id ) ) {
return true;
}
return rcp_user_can_view_woocommerce_product( get_current_user_id(), $product_id );
}
/**
* Loads the restricted content template if required.
*
* @param string $template
* @param string $slug
* @param string $name
*
* @access public
* @since 2.5
* @return string
*/
public function hide_template( $template, $slug, $name ) {
$product_id = get_the_ID();
if ( ! is_singular( 'product' ) ) {
return $template;
}
if( 'content-single-product' !== $slug . '-' . $name ) {
return $template;
}
if ( current_user_can( 'edit_post', $product_id ) ) {
return $template;
}
if ( rcp_user_can_view_woocommerce_product( get_current_user_id(), $product_id ) ) {
return $template;
}
return rcp_get_template_part( 'woocommerce', 'single-no-access', false );
}
}
new RCP_WooCommerce;
/**
* Determines whether or not a user is allowed to purchase a WooCommerce product.
*
* @param int $user_id ID of the user to check.
* @param int $product_id ID of the WooCommerce product.
*
* @since 3.0.6
* @return bool
*/
function rcp_user_can_purchase_woocommerce_product( $user_id, $product_id ) {
$customer = rcp_get_customer_by_user_id( $user_id );
$can_purchase = true;
$active_only = get_post_meta( $product_id, '_rcp_woo_active_to_purchase', true );
$levels = (array) get_post_meta( $product_id, '_rcp_woo_subscription_levels_to_purchase', true );
$access_level = get_post_meta( $product_id, '_rcp_woo_access_level_to_purchase', true );
$levels = array_filter( $levels );
if ( ! empty( $active_only ) || ! empty( $levels ) || ! empty( $access_level ) ) {
// Product has some kind of restrictions.
if ( ! empty( $customer ) && $customer->is_pending_verification() ) {
// Customer is pending email verification so they should not get access.
$can_purchase = false;
}
}
// Requires an active membership.
if ( $active_only ) {
if ( empty( $customer ) || ! $customer->has_active_membership() ) {
$can_purchase = false;
}
}
// Requires a specific membership level.
if ( is_array( $levels ) && ! empty( $levels ) ) {
if ( empty( $customer ) || ! count( array_intersect( rcp_get_customer_membership_level_ids( $customer->get_id() ), $levels ) ) ) {
$can_purchase = false;
}
}
if ( $access_level ) {
if ( empty( $customer ) || ! $customer->has_access_level( $access_level ) ) {
$can_purchase = false;
}
}
/**
* Filters whether or not the user has permission to purchase this product.
*
* @param bool $can_purchase Whether or not the user is allowed to purchase the product.
* @param int $user_id ID of the user being checked.
* @param int $product_id ID of the product being checked.
*
* @since 3.0.6
*/
return apply_filters( 'rcp_user_can_purchase_woocommerce_product', $can_purchase, $user_id, $product_id );
}
/**
* Determines whether or not a user is allowed to view a WooCommerce product.
*
* @param int $user_id ID of the user to check.
* @param int $product_id ID of the WooCommerce product.
*
* @since 3.0.6
* @return bool
*/
function rcp_user_can_view_woocommerce_product( $user_id, $product_id ) {
$customer = rcp_get_customer_by_user_id( $user_id );
$can_view = true;
$active_only = get_post_meta( $product_id, '_rcp_woo_active_to_view', true );
$levels = (array) get_post_meta( $product_id, '_rcp_woo_subscription_levels_to_view', true );
$access_level = get_post_meta( $product_id, '_rcp_woo_access_level_to_view', true );
$levels = array_filter( $levels );
if ( ! empty( $active_only ) || ! empty( $levels ) || ! empty( $access_level ) ) {
// Product has some kind of restrictions.
if ( ! empty( $customer ) && $customer->is_pending_verification() ) {
// Customer is pending email verification so they should not get access.
$can_view = false;
}
}
if ( $active_only ) {
if ( empty( $customer ) || ! $customer->has_active_membership() ) {
$can_view = false;
}
}
if ( is_array( $levels ) && ! empty( $levels ) ) {
if ( empty( $customer ) || ! count( array_intersect( rcp_get_customer_membership_level_ids( $customer->get_id() ), $levels ) ) ) {
$can_view = false;
}
}
if ( $access_level ) {
if ( empty( $customer ) || ! $customer->has_access_level( $access_level ) ) {
$can_view = false;
}
}
if ( true === rcp_is_post_taxonomy_restricted( $product_id, 'product_cat', $user_id ) ) {
$can_view = false;
}
if ( true === rcp_is_post_taxonomy_restricted( $product_id, 'product_tag', $user_id ) ) {
$can_view = false;
}
/**
* Filters whether or not the user has permission to view this product.
*
* @param bool $can_view Whether or not the user is allowed to view the product.
* @param int $user_id ID of the user being checked.
* @param int $product_id ID of the product being checked.
*
* @since 3.0.6
*/
return apply_filters( 'rcp_user_can_view_woocommerce_product', $can_view, $user_id, $product_id );
}

View File

@@ -0,0 +1,285 @@
<?php
/**
* WP Approve User Integration
*
* @package Restrict Content Pro
* @subpackage Integrations/WP Approve User
* @copyright Copyright (c) 2017, Restrict Content Pro
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 2.4
*/
class RCP_WP_Approve_User {
/**
* Get things started
*
* @access public
* @since 2.4
*/
public function __construct() {
if( ! class_exists( 'Obenland_Wp_Approve_User' ) ) {
return;
}
$this->init();
}
/**
* Add actions and filters
*
* @access public
* @since 2.4
*/
public function init() {
add_filter( 'option_users_can_register', array( $this, 'users_can_register' ) );
add_filter( 'rcp_member_can_access', array( $this, 'can_access' ), 10, 4 );
add_filter( 'rcp_restrict_shortcode_has_access', array( $this, 'can_access_shortcode_content' ), 10, 3 );
add_filter( 'rcp_restricted_message', array( $this, 'pending_message' ), 9999 );
add_action( 'signup_header', array( $this, 'redirect_wp_signup' ) );
add_action( 'rcp_member_row_actions', array( $this, 'member_row_actions' ) );
add_action( 'admin_init', array( $this, 'process_approve' ) );
add_action( 'admin_init', array( $this, 'process_unapprove' ) );
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
}
/**
* Determine if member is pending
*
* @param int $user_id
*
* @access public
* @since 2.4
* @return bool
*/
private function is_pending( $user_id = 0 ) {
return (bool) is_user_logged_in() && ! get_user_meta( $user_id, 'wp-approve-user', true ) && ! user_can( $user_id, 'edit_pages' );
}
/**
* Force can register option on
*
* @access public
* @since 2.4
* @return bool
*/
public function users_can_register() {
return true;
}
/**
* Prevent users from accessing the default registration screen
*
* @access public
* @since 2.4
* @return void
*/
public function redirect_wp_signup() {
global $rcp_options;
$redirect = isset( $rcp_options['registration_page'] ) ? get_permalink( $rcp_options['registration_page'] ) : home_url();
wp_redirect( $redirect ); exit;
}
/**
* Block pending members from seeing content
*
* @param bool $can_access
* @param int $member_id
* @param int $post_id
* @param RCP_Member $member
*
* @access public
* @since 2.4
* @return bool
*/
public function can_access( $can_access, $member_id, $post_id, $member ) {
if ( ! rcp_is_restricted_content( $post_id ) ) {
return $can_access;
}
if ( $this->is_pending( $member_id ) ) {
$can_access = false;
}
return $can_access;
}
/**
* Block pending members from seeing content protected with [restrict]
*
* @param bool $can_access
* @param int $member_id
* @param array $atts Shortcode attributes.
*
* @access public
* @since 2.5.4
* @return bool
*/
public function can_access_shortcode_content( $can_access, $member_id, $atts ) {
if ( $can_access && $this->is_pending( $member_id ) ) {
$can_access = false;
}
return $can_access;
}
/**
* Display pending verification message when trying to access restricted content
*
* @param string $message
*
* @access public
* @since 2.4
* @return string
*/
public function pending_message( $message ) {
global $rcp_load_css;
$rcp_load_css = true;
if( $this->is_pending( get_current_user_id() ) ) {
$message = '<div class="rcp_message error"><p class="rcp_error rcp_pending_member"><span>' . __( 'Your account is pending verification by a site administrator.', 'rcp' ) . '</span></p></div>';
}
return $message;
}
/**
* Display Approve | Unapprove links on member rows
*
* @param int $member_id
*
* @access public
* @since 2.4
* @return void
*/
public function member_row_actions( $member_id ) {
$site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
$url = 'admin.php?page=rcp-members';
if ( ! $this->is_pending( $member_id ) ) {
$url = wp_nonce_url( add_query_arg( array(
'action' => 'rcp_wpau_unapprove',
'user' => urlencode( $member_id )
), $url ), 'wpau-unapprove-user' );
printf( ' | <a class="submitunapprove" href="%1$s">%2$s</a>', esc_url( $url ), __( 'Unapprove', 'rcp' ) );
} else {
$url = wp_nonce_url( add_query_arg( array(
'action' => 'rcp_wpau_approve',
'user' => urlencode( $member_id )
), $url ), 'wpau-approve-user' );
printf( ' | <a class="submitapprove" href="%1$s">%2$s</a>', esc_url( $url ), __( 'Approve', 'rcp' ) );
}
}
/**
* Approve a user
*
* @access public
* @since 2.4
* @return void
*/
public function process_approve() {
if( empty( $_REQUEST['action'] ) || 'rcp_wpau_approve' !== $_REQUEST['action'] ) {
return;
}
check_admin_referer( 'wpau-approve-user' );
if( ! current_user_can( 'edit_user', $_REQUEST['user'] ) ) {
wp_die( __( 'You do not have permission to edit this user', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 403 ) );
}
update_user_meta( $_REQUEST['user'], 'wp-approve-user', true );
do_action( 'wpau_approve', $_REQUEST['user'] );
wp_redirect( add_query_arg( array(
'action' => 'rcp_wpau_update',
'update' => 'wpau-approved',
'count' => 1
), admin_url( 'admin.php?page=rcp-members' ) ) );
exit;
}
/**
* Unapprove a user
*
* @access public
* @since 2.4
* @return void
*/
public function process_unapprove() {
if( empty( $_REQUEST['action'] ) || 'rcp_wpau_unapprove' !== $_REQUEST['action'] ) {
return;
}
check_admin_referer( 'wpau-unapprove-user' );
if( ! current_user_can( 'edit_user', $_REQUEST['user'] ) ) {
wp_die( __( 'You do not have permission to edit this user', 'rcp' ), __( 'Error', 'rcp' ), array( 'response' => 403 ) );
}
update_user_meta( $_REQUEST['user'], 'wp-approve-user', false );
do_action( 'wpau_unapprove', $_REQUEST['user'] );
wp_redirect( add_query_arg( array(
'action' => 'rcp_wpau_update',
'update' => 'wpau-unapproved',
'count' => 1
), admin_url( 'admin.php?page=rcp-members' ) ) );
exit;
}
/**
* Show admin notices
*
* @access public
* @since 2.4
* @return void
*/
public function admin_notices() {
if( empty( $_REQUEST['action'] ) || 'rcp_wpau_update' !== $_REQUEST['action'] ) {
return;
}
if( empty( $_REQUEST['update'] ) ) {
return;
}
if( 'wpau-unapproved' == $_REQUEST['update'] ) {
$text = __( 'Member unapproved', 'rcp' );
} else {
$text = __( 'Member approved', 'rcp' );
}
echo '<div class="updated"><p>' . $text . '</p></div>';
}
}
new RCP_WP_Approve_User;

View File

@@ -0,0 +1 @@
<?php // Silence is golden.