HEX

Warning: set_time_limit() [function.set-time-limit]: Cannot set time limit - prohibited by configuration in /home/u547966/brikov.ru/www/wp-content/plugins/admin-menu-editor/menu-editor.php on line 745
Server: Apache
System: Linux 4.19.0-0.bpo.9-amd64 x86_64 at red40
User: u547966 (5490)
PHP: 5.3.29-mh2
Disabled: syslog, dl, popen, proc_open, proc_nice, proc_get_status, proc_close, proc_terminate, posix_mkfifo, chown, chgrp, accelerator_reset, opcache_reset, accelerator_get_status, opcache_get_status, pcntl_alarm, pcntl_fork, pcntl_waitpid, pcntl_wait, pcntl_wifexited, pcntl_wifstopped, pcntl_wifsignaled, pcntl_wifcontinued, pcntl_wexitstatus, pcntl_wtermsig, pcntl_wstopsig, pcntl_signal, pcntl_signal_dispatch, pcntl_get_last_error, pcntl_strerror, pcntl_sigprocmask, pcntl_sigwaitinfo, pcntl_sigtimedwait, pcntl_exec, pcntl_getpriority, pcntl_setpriority
Upload Files
File: //proc/self/cwd/wp-content/plugins/groups/lib/access/class-groups-access-shortcodes.php
<?php
/**
 * class-groups-access-shortcodes.php
 *
 * Copyright (c) "kento" Karim Rahimpur www.itthinx.com
 *
 * This code is released under the GNU General Public License.
 * See COPYRIGHT.txt and LICENSE.txt.
 *
 * This code 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.
 *
 * This header and all notices must be kept intact.
 *
 * @author Karim Rahimpur
 * @package groups
 * @since groups 1.0.0
 */

if ( !defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Shortcode handlers.
 */
class Groups_Access_Shortcodes {

	/**
	 * Defines access shortcodes.
	 */
	public static function init() {

		// group restrictions
		add_shortcode( 'groups_member', array( __CLASS__, 'groups_member' ) );
		add_shortcode( 'groups_non_member', array( __CLASS__, 'groups_non_member' ) );

		// capabilities
		add_shortcode( 'groups_can', array( __CLASS__, 'groups_can' ) );
		add_shortcode( 'groups_can_not', array( __CLASS__, 'groups_can_not' ) );
	}

	/**
	 * Takes one attribute "group" which is a comma-separated list of group
	 * names or ids (can be mixed).
	 *
	 * The content is shown if the current user belongs to the group(s).
	 *
	 * @param array $atts attributes
	 * @param string $content content to render
	 *
	 * @return string
	 */
	public static function groups_member( $atts, $content = null ) {
		$output = '';
		$options = shortcode_atts( array( 'group' => '' ), $atts );
		$show_content = false;
		if ( $content !== null ) {
			$groups_user = new Groups_User( get_current_user_id() );
			$groups = explode( ',', $options['group'] );
			foreach ( $groups as $group ) {
				$group = addslashes( trim( $group ) );
				$current_group = Groups_Group::read( $group );
				if ( !$current_group ) {
					$current_group = Groups_Group::read_by_name( $group );
				}
				if ( $current_group ) {
					if ( $groups_user->is_member( $current_group->group_id ) ) {
						$show_content = true;
						break;
					}
				}
			}
			if ( $show_content ) {
				remove_shortcode( 'groups_member' );
				$content = do_shortcode( $content );
				add_shortcode( 'groups_member', array( __CLASS__, 'groups_member' ) );
				$output = $content;
			}
		}
		return $output;
	}

	/**
	 * Takes one attribute "group" which is a comma-separated list of group
	 * names or ids (can be mixed).
	 *
	 * The content is shown if the current user does NOT belong to the group(s).
	 *
	 * @param array $atts attributes
	 * @param string $content content to render
	 *
	 * @return string
	 */
	public static function groups_non_member( $atts, $content = null ) {
		$output = '';
		$options = shortcode_atts( array( 'group' => '' ), $atts );
		$show_content = true;
		if ( $content !== null ) {
			$groups_user = new Groups_User( get_current_user_id() );
			$groups = explode( ',', $options['group'] );
			foreach ( $groups as $group ) {
				$group = addslashes( trim( $group ) );
				$current_group = Groups_Group::read( $group );
				if ( !$current_group ) {
					$current_group = Groups_Group::read_by_name( $group );
				}
				if ( $current_group ) {
					if ( $groups_user->is_member( $current_group->group_id ) ) {
						$show_content = false;
						break;
					}
				}
			}
			if ( $show_content ) {
				remove_shortcode( 'groups_non_member' );
				$content = do_shortcode( $content );
				add_shortcode( 'groups_non_member', array( __CLASS__, 'groups_non_member' ) );
				$output = $content;
			}
		}
		return $output;
	}

	/**
	 * Takes one attribute "capability" that must be a valid capability label
	 * or a list of capabilities separated by comma.
	 *
	 * The content is shown if the current user has one of the capabilities.
	 *
	 * @param array $atts attributes
	 * @param string $content content to render
	 *
	 * @return string
	 */
	public static function groups_can( $atts, $content = null ) {
		$output = '';
		$options = shortcode_atts( array( 'capability' => '' ), $atts );
		if ( $content !== null ) {
			$groups_user = new Groups_User( get_current_user_id() );
			$capability = $options['capability'];
			$capabilities = array_map( 'trim', explode( ',', $capability ) );
			$show_content = false;
			foreach( $capabilities as $capability ) {
				if ( $groups_user->can( $capability ) ) {
					$show_content = true;
					break;
				}
			}
			if ( $show_content ) {
				remove_shortcode( 'groups_can' );
				$content = do_shortcode( $content );
				add_shortcode( 'groups_can', array( __CLASS__, 'groups_can' ) );
				$output = $content;
			}
		}
		return $output;
	}

	/**
	 * Takes one attribute "capability" that must be a valid capability label,
	 * or a comma-separated list of those.
	 *
	 * The content is shown if the current user has none of the capabilities.
	 *
	 * @param array $atts attributes
	 * @param string $content content to render
	 *
	 * @return string
	 */
	public static function groups_can_not( $atts, $content = null ) {
		$output = '';
		$options = shortcode_atts( array( 'capability' => '' ), $atts );
		if ( $content !== null ) {
			$groups_user = new Groups_User( get_current_user_id() );
			$capability = $options['capability'];
			$capabilities = array_map( 'trim', explode( ',', $capability ) );
			$show_content = true;
			foreach( $capabilities as $capability ) {
				if ( $groups_user->can( $capability ) ) {
					$show_content = false;
					break;
				}
			}
			if ( $show_content ) {
				remove_shortcode( 'groups_can_not' );
				$content = do_shortcode( $content );
				add_shortcode( 'groups_can_not', array( __CLASS__, 'groups_can_not' ) );
				$output = $content;
			}
		}
		return $output;
	}
}
Groups_Access_Shortcodes::init();