*/
class Cookie_Law_Info_Admin {
/**
* The ID of this plugin.
*
* @since 1.6.6
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.6.6
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
public $plugin_obj;
/*
* admin module list, Module folder and main file must be same as that of module name
* Please check the `admin_modules` method for more details
*/
private $modules=array(
'cli-policy-generator',
'ccpa',
'uninstall-feedback',
);
public static $existing_modules=array();
/**
* Initialize the class and set its properties.
*
* @since 1.6.6
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version,$plugin_obj ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->plugin_obj = $plugin_obj;
}
/**
* Register the stylesheets for the admin area.
*
* @since 1.6.6
*/
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 Cookie_Law_Info_Loader as all of the hooks are defined
* in that particular class.
*
* The Cookie_Law_Info_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( 'wp-color-picker' );
wp_register_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/cookie-law-info-admin.css', array(), $this->version, 'all' );
}
/**
* Register the JavaScript for the admin area.
*
* @since 1.6.6
*/
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 Cookie_Law_Info_Loader as all of the hooks are defined
* in that particular class.
*
* The Cookie_Law_Info_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_register_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/cookie-law-info-admin.js', array( 'jquery' ,'wp-color-picker'), $this->version, false );
}
/**
Registers admin modules
*/
public function admin_modules()
{
foreach ($this->modules as $module) //loop through module list and include its file
{
$module_file=plugin_dir_path( __FILE__ )."modules/$module/$module.php";
if(file_exists($module_file))
{
self::$existing_modules[]=$module; //this is for module_exits checking
require_once $module_file;
}
}
}
public static function module_exists($module)
{
return in_array($module,self::$existing_modules);
}
/**
Registers menu options
Hooked into admin_menu
*/
public function admin_menu() {
global $submenu;
add_submenu_page(
'edit.php?post_type='.CLI_POST_TYPE,
__('Cookie Law Settings','cookie-law-info'),
__('Cookie Law Settings','cookie-law-info'),
'manage_options',
'cookie-law-info',
array($this,'admin_settings_page')
);
add_submenu_page(
'edit.php?post_type='.CLI_POST_TYPE,
__('Non-necessary Cookie','cookie-law-info'),
__('Non-necessary Cookie','cookie-law-info'),
'manage_options',
'cookie-law-info-thirdparty',
array($this,'admin_non_necessary_cookie_page')
);
add_submenu_page(
'edit.php?post_type='.CLI_POST_TYPE,
__('Necessary Cookie','cookie-law-info'),
__('Necessary Cookie','cookie-law-info'),
'manage_options',
'cookie-law-info-necessary',
array($this,'admin_necessary_cookie_page')
);
add_submenu_page(
'edit.php?post_type='.CLI_POST_TYPE,
__('Privacy Overview','cookie-law-info'),
__('Privacy Overview','cookie-law-info'),
'manage_options',
'cookie-law-info-poverview',
array($this,'privacy_overview_page')
);
//rearrange settings menu
if(isset($submenu) && !empty($submenu) && is_array($submenu))
{
$out=array();
$back_up_settings_menu=array();
if(isset($submenu['edit.php?post_type='.CLI_POST_TYPE]) && is_array($submenu['edit.php?post_type='.CLI_POST_TYPE]))
{
foreach ($submenu['edit.php?post_type='.CLI_POST_TYPE] as $key => $value)
{
if($value[2]=='cookie-law-info')
{
$back_up_settings_menu=$value;
}else
{
$out[$key]=$value;
}
}
array_unshift($out,$back_up_settings_menu);
$submenu['edit.php?post_type='.CLI_POST_TYPE]=$out;
}
}
}
/*
* Privacy overview CMS page
* @since 1.7.7
*/
public function privacy_overview_page()
{
wp_enqueue_style($this->plugin_name);
require_once plugin_dir_path( __FILE__ ).'partials/cookie-law-info-privacy_overview.php';
}
public function plugin_action_links( $links )
{
$links[] = ''.__('Settings','cookie-law-info').'';
$links[] = ''.__('Support','cookie-law-info').'';
$links[] = ''.__('Premium Upgrade','cookie-law-info').'';
return $links;
}
public function admin_non_necessary_cookie_page()
{
wp_enqueue_style($this->plugin_name);
wp_enqueue_script($this->plugin_name);
if (!current_user_can('manage_options'))
{
wp_die(__('You do not have sufficient permission to perform this operation', 'cookie-law-info'));
}
$options = array('thirdparty_on_field',
'third_party_default_state',
'thirdparty_description',
'thirdparty_head_section',
'thirdparty_body_section',
//'thirdparty_footer_section',
);
// Get options:
$stored_options = get_option('cookielawinfo_thirdparty_settings', array(
'thirdparty_on_field' => false,
'third_party_default_state' => true,
'thirdparty_description'=> '',
'thirdparty_head_section' => '',
'thirdparty_body_section' => '',
//'thirdparty_footer_section' => '',
));
// Check if form has been set:
if (
isset($_POST['update_thirdparty_settings_form']) || //normal php submit
isset($_POST['cli_non-necessary_ajax_update'])
)
{
// Check nonce:
check_admin_referer('cookielawinfo-update-thirdparty');
$stored_options['thirdparty_on_field'] = (bool)( isset( $_POST['thirdparty_on_field'] ) ? Cookie_Law_Info::sanitise_settings('thirdparty_on_field',$_POST['thirdparty_on_field']) : false );
$stored_options['third_party_default_state'] = (bool)( isset( $_POST['third_party_default_state'] ) ? Cookie_Law_Info::sanitise_settings('third_party_default_state',$_POST['third_party_default_state']) : true );
$stored_options['thirdparty_description'] = wp_kses_post( isset( $_POST['thirdparty_description'] ) && $_POST['thirdparty_description'] !== '' ? $_POST['thirdparty_description'] : '' );
$stored_options['thirdparty_head_section'] = wp_unslash( isset( $_POST['thirdparty_head_section'] ) && $_POST['thirdparty_head_section'] !== '' ? $_POST['thirdparty_head_section'] : '' );
$stored_options['thirdparty_body_section'] = wp_unslash( isset( $_POST['thirdparty_body_section'] ) && $_POST['thirdparty_body_section'] !== '' ? $_POST['thirdparty_body_section'] : '' );
update_option('cookielawinfo_thirdparty_settings', $stored_options);
echo '