*/
class Age_Gate_Admin {
/**
* The options name to be used in this plugin
*
* @since 1.0.0
* @access private
* @var string $option_name Option name of this plugin
*/
private $option_name = 'wp_age_gate';
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
/**
* Plugin info.
*
* @since 1.4.6
* @access private
* @var string $plugin_info The current data of this plugin.
*/
private $plugin_info;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->settings = get_option($this->option_name . '_general');
// $this->display_version = $this->_plugin_get_version();
if(!function_exists('get_plugin_data')){
// wp_die(ABSPATH);
require_once( ABSPATH . "wp-admin/includes/plugin.php" );
}
$this->plugin_info = get_plugin_data(AGE_GATE_DIR . '/age-gate.php', false, false);
$this->_updateCheck();
}
/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Age_Gate_Loader as all of the hooks are defined
* in that particular class.
*
* The Age_Gate_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
global $pagenow;
if( $pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] === 'age-gate'){
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/age-gate-admin.css', array(), $this->version, 'all' );
}
}
/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Age_Gate_Loader as all of the hooks are defined
* in that particular class.
*
* The Age_Gate_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
global $pagenow;
if( $pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] === 'age-gate'){
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script('wplink');
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/age-gate-admin.js', array( 'jquery', 'wp-color-picker' ), $this->version, false );
}
}
/**
* Register plugin menu item
*
* @since 1.0.0 Displays the menu
*/
public function add_menu_section()
{
$this->plugin_page_hook_suffix = add_menu_page(
__('Age Gate', $this->plugin_name),
__('Age Gate', $this->plugin_name),
'edit_pages',
$this->plugin_name,
array($this, 'display_options_page'),
'dashicons-lock',
60
);
}
/**
* Create a settings link in the plugins screen
*
* @param mixed $links The standard links
* @return mixed $links The links updated with our settings
* @since 1.0.0
*/
public function plugin_add_settings_link( $links ) {
$settings_link = '' . __( 'Settings', $this->plugin_name ) . '';
$donate_link = '' . __( 'Donate', $this->plugin_name ) . '';
array_unshift( $links, $settings_link );
array_push( $links, $donate_link );
return $links;
}
/**
* Add manage_options
*
* In order to save as editor, they need this
* @since 1.0.0
*/
public function add_manage_options()
{
return 'edit_pages';
}
/**
* Add the option to restrict specific content
*
* @since 1.0.0
*/
public function restrict_select_content()
{
?>
';
}
/**
* Callback for link picker
* @since 1.3.0
*/
public function wp_age_gate_link_field_cb($args){
//
// Fix for pages that don't have editors
add_action('admin_print_footer_scripts', function () {
if ( ! class_exists('_WP_Editors') and ( ! defined('DOING_AJAX') or ! DOING_AJAX)) {
require_once ABSPATH.WPINC.'/class-wp-editor.php';
wp_print_styles('editor-buttons');
_WP_Editors::wp_link_dialog();
}
});
echo '
';
echo '' ;
echo '' ;
}
/**
* Render the text for the general section
*
* @since 1.0.0
*/
public function wp_age_gate_general_cb($args)
{
switch($args['id']){
case $this->option_name . '_style':
echo '
' . __( 'Update the look of the age gate.', $this->plugin_name ) . '
';
break;
case $this->option_name . '_messaging':
echo '
' . __( 'Set the messages users see on the age gate.', $this->plugin_name ) . ' Note: Adding “%s” to any of these fields will output the minimum age
';
break;
case $this->option_name . '_misc':
echo '
';
break;
case $this->option_name . '_caching':
echo '
' . __( 'If you have a caching solution, it is best to use a JavaScript triggered version of the age gate as this won’t be adversely affected by the cache. If you don’t have caching, the standard method is recommended.', $this->plugin_name ) . '
';
break;
default:
echo '
' . __( 'Set the restrictions for your site.', $this->plugin_name ) . '
';
}
}
/**
* Callback to display media selector
* @param mixed $args
* @since 1.0.0
*/
public function wp_age_gate_media_selector_cb($args) {
wp_enqueue_media();
?>
' style="max-height: 100px">
plugin_name) . '" data-option="'. $this->option_name . $args['field_name'] .'" />';
}
}
/**
* Callback to display remove fields from tinymce
* @param mixed $args
* @since 1.0.0
*/
public function wp_age_gate_customise_tinymce($buttons)
{
$removeButtons = array('formatselect','blockquote','alignleft','aligncenter','alignright','wp_more','fullscreen','wp_adv');
foreach ($buttons as $button_key => $button_value) {
if( in_array($button_value, $removeButtons )){
unset($buttons[$button_key]);
}
}
return $buttons;
}
/**
* Checks the plugin version against the stored version
* and updates the settings if mismatched
*
* @since 1.1.0
*
*/
private function _updateCheck()
{
if ($this->version !== get_option('wp_age_gate_version')){
require_once AGE_GATE_DIR . 'includes/class-age-gate-activator.php';
Age_Gate_Activator::activate();
update_option('wp_age_gate_version', $this->version);
}
}
/**
* Set notices
* @since 1.4.0
*/
public function set_notices($value, $option = null, $old_value = null)
{
if($value['wp_age_gate_use_js'] === 'js'){
set_transient('wp_age_gate_notice', array(
array(
'message' => __('You are using the "Cache Bypass" implementation, if you have caching enabled ensure you purge it to see your changes', $this->plugin_name),
'class' => 'notice-warning'
)
)
);
}
return $value;
}
/**
* Set WPeC notice
* @since 1.4.6
*/
public function set_wpec_notice()
{
global $pagenow;
if( $pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] === 'age-gate' && !isset($_GET['tab']) || $pagenow == 'plugins.php'){
echo '
'. ($pagenow == 'plugins.php' ? 'AGE GATE ' : '') .'NOTICE: WP eCommerce does not support Standard mode, Cache bypass has been enabled.
';
}
}
/**
* Show admin notices
* @since 1.4.0
*/
public function show_admin_notice(){
global $pagenow;
if( $pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] === 'age-gate'){
$notices = get_transient('wp_age_gate_notice');
if( $notices !== false ){
foreach( $notices as $notice ){
echo '
NOTICE: ' . $notice['message'] . '
';
}
delete_transient('wp_age_gate_notice');
}
}
}
public function plugins_load_order() {
// ensure path to this file is via main wp plugin path
$wp_path_to_this_file = preg_replace('/(.*)plugins\/(.*)$/', WP_PLUGIN_DIR."/$2", AGE_GATE_DIR . 'age-gate.php');
$this_plugin = plugin_basename(trim($wp_path_to_this_file));
$active_plugins = get_option('active_plugins');
$this_plugin_key = array_search($this_plugin, $active_plugins);
// if ($this_plugin_key) { // if it's 0 it's the first plugin already, no need to continue
array_splice($active_plugins, $this_plugin_key, 1);
array_push($active_plugins, $this_plugin);
update_option('active_plugins', $active_plugins);
// }
//
// echo "
";
// print_r($active_plugins);
// wp_die();
}
public static function _force_js()
{
return is_plugin_active('wp-e-commerce/wp-shopping-cart.php');
}
}