_update_check();
}
/**
* 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.
*/
wp_enqueue_style( $this->plugin_name, AGE_GATE_URL . 'admin/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.
*/
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script('wplink');
wp_enqueue_script( $this->plugin_name, AGE_GATE_URL . 'admin/js/age-gate-admin.js', array( 'jquery', 'wp-color-picker' ), $this->version, false );
wp_localize_script( $this->plugin_name, 'ag', $this->_localize() );
}
/**
* Register global 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),
AGE_GATE_CAP_RESTRICTIONS,
$this->plugin_name,
'__return_false',//array($this, 'display_options_page'),
'dashicons-lock',
60
);
}
public function age_gate_admin_notice() {
if ($messages = get_transient('age_gate_admin_notice')) {
foreach ($messages as $key => $message) {
echo '
'. $message['message'] .'
';
}
}
if(current_user_can(AGE_GATE_CAP_ACCESS)){
$this->_dev_notices();
}
delete_transient('age_gate_admin_notice');
delete_transient('age_gate_admin_notice_css');
}
private function _dev_notices()
{
$data = get_plugin_data( AGE_GATE_PATH . 'age-gate.php' );
$sub = explode('-', ($data['Version']));
if(isset($sub[1]) && !empty($sub[1]) && !$this->settings['advanced']['dev_hide_warning']){
if($this->settings['advanced']['dev_notify'] && $new = $this->_checkLatest($sub[1])){
$messageText = sprintf(__('A new development version of Age Gate has been released. %s is the latest build, you have %s.', AGE_GATE_TEXT_DOMAIN), $new, $sub[1]);
echo '';
}
$messageText = sprintf(__('You are using the %s version of Age Gate. This may not be suitable for production websites.', AGE_GATE_TEXT_DOMAIN), $sub[1]);
echo '';
}
}
public function editor_scripts(){
global $pagenow;
if(isset($_REQUEST['page']) && strpos($_REQUEST['page'], 'age-gate') !== false){
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();
}
}
}
/**
* 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_action_links( $links ) {
$settings_link = '' . __( 'Settings', AGE_GATE_TEXT_DOMAIN ) . '';
$donate_link = '' . __( 'Donate', AGE_GATE_TEXT_DOMAIN ) . '';
array_unshift( $links, $settings_link );
array_push( $links, $donate_link );
return $links;
}
/**
* Create a link to website
*
* @param mixed $plugin_meta The standard links
* @return mixed $plugin_file The links updated with our settings
* @since 2.0.0
*/
public function website_link( $plugin_meta, $plugin_file ) {
$basename = plugin_basename(AGE_GATE_PATH) . '/age-gate.php';
if ( $basename === $plugin_file ) {
$plugin_meta[] = sprintf(
'%s',
'https://wordpressagegate.com/docs',
esc_html__( 'Documentation', AGE_GATE_TEXT_DOMAIN )
);
}
return $plugin_meta;
}
private function _localize()
{
return array(
'uploader' => array(
'title' => _x('Select an image to upload', 'Image uploader text', AGE_GATE_TEXT_DOMAIN),
'button' => _x('Use this image', 'Image uploader button', AGE_GATE_TEXT_DOMAIN),
'remove_image' => __('Remove image', AGE_GATE_TEXT_DOMAIN),
),
'link' => array(
'remove_link' => __('Remove link', AGE_GATE_TEXT_DOMAIN),
'custom' => __('Custom', AGE_GATE_TEXT_DOMAIN)
),
'css' => array(
'warning' => __('There are warnings in your CSS. You can save your changes, but there may be display issues.', AGE_GATE_TEXT_DOMAIN),
'error' => __('There are errors in your CSS. Please fix these before saving.', AGE_GATE_TEXT_DOMAIN),
),
'update_confirm' => array(
'warning' => _x('I have read the warning and understand updating could cause unexpected results.', 'Warning message presented when trying to update between major versions', AGE_GATE_TEXT_DOMAIN),
'confirm' => _x('You can now proceed with the update', 'Confirm message presented on enabling update', AGE_GATE_TEXT_DOMAIN)
)
);
}
/**
* Checks the plugin version against the stored version
* and updates the settings if mismatched
*
* @since 1.1.0
*
*/
private function _update_check()
{
if (AGE_GATE_VERSION !== get_option('wp_age_gate_version')){
require_once AGE_GATE_PATH . 'includes/class-age-gate-activator.php';
Age_Gate_Activator::activate();
// update_option('wp_age_gate_version', AGE_GATE_VERSION);
}
}
/**
* Forces use of JS age gate in some cases
* @return [type] [description]
*/
public static function force_js()
{
if(!function_exists('is_plugin_active')){
// wp_die(ABSPATH);
require_once( ABSPATH . "wp-admin/includes/plugin.php" );
}
return is_plugin_active('wp-e-commerce/wp-shopping-cart.php');
}
private function _checkLatest($current)
{
$x = @file_get_contents('https://wordpressagegate.com/api/downloads/v1/latest');
if($x){
$x = str_replace('"', '', $x);
}
if(!version_compare($current, $x, ">=")){
return $x;
}
}
}