%1$s %2$s
', esc_html__( 'DISALLOW_FILE_EDIT is defined. You should also disallow PHP execution in GP Hooks.', 'gp-premium' ), esc_html__( 'Learn how', 'gp-premium' ) ); } } } if ( ! function_exists( 'generate_hooks_setup' ) ) { function generate_hooks_setup() { // Just to verify that we're activated. } } if ( ! class_exists( 'Generate_Hooks_Settings' ) ) { class Generate_Hooks_Settings { private $dir; private $file; private $assets_dir; private $assets_url; private $settings_base; private $settings; public function __construct( $file ) { $this->file = $file; $this->dir = dirname( $this->file ); $this->assets_dir = trailingslashit( $this->dir ) . 'assets'; $this->assets_url = esc_url( trailingslashit( plugins_url( '/assets/', $this->file ) ) ); $this->settings_base = ''; // Initialise settings add_action( 'admin_init', array( $this, 'init' ) ); // Register plugin settings add_action( 'admin_init' , array( $this, 'register_settings' ) ); // Add settings page to menu add_action( 'admin_menu' , array( $this, 'add_menu_item' ) ); // Add settings link to plugins page add_filter( 'plugin_action_links_' . plugin_basename( $this->file ) , array( $this, 'add_settings_link' ) ); } /** * Initialise settings * @return void */ public function init() { $this->settings = $this->settings_fields(); } /** * Add settings page to admin menu * @return void */ public function add_menu_item() { $page = add_theme_page( __( 'GP Hooks', 'gp-premium' ) , __( 'GP Hooks', 'gp-premium' ) , apply_filters( 'generate_hooks_capability','manage_options' ) , 'gp_hooks_settings' , array( $this, 'settings_page' ) ); add_action( 'admin_print_styles-' . $page, array( $this, 'settings_assets' ) ); } /** * Load settings JS & CSS * @return void */ public function settings_assets() { wp_enqueue_script( 'gp-cookie', $this->assets_url . 'js/jquery.cookie.js', array( 'jquery' ), GENERATE_HOOKS_VERSION ); wp_enqueue_script( 'gp-hooks', $this->assets_url . 'js/admin.js', array( 'jquery', 'gp-cookie' ), GENERATE_HOOKS_VERSION ); wp_enqueue_style( 'gp-hooks', $this->assets_url . 'css/hooks.css' ); } /** * Add settings link to plugin list table * @param array $links Existing links * @return array Modified links */ public function add_settings_link( $links ) { $settings_link = '' . __( 'GP Hooks', 'gp-premium' ) . ''; array_push( $links, $settings_link ); return $links; } /** * Build settings fields * @return array Fields to be displayed on settings page */ private function settings_fields() { $settings['standard'] = array( 'title' => '', 'description' => '', 'fields' => array( array( "name" => __( 'wp_head', 'gp-premium' ), "id" => 'generate_wp_head', "type" => 'textarea' ), array( "name" => __( 'Before Header', 'gp-premium' ), "id" => 'generate_before_header', "type" => 'textarea' ), array( "name" => __( 'Before Header Content', 'gp-premium' ), "id" => 'generate_before_header_content', "type" => 'textarea' ), array( "name" => __( 'After Header Content', 'gp-premium' ), "id" => 'generate_after_header_content', "type" => 'textarea' ), array( "name" => __( 'After Header', 'gp-premium' ), "id" => 'generate_after_header', "type" => 'textarea' ), array( "name" => __( 'Inside Content Container', 'gp-premium' ), "id" => 'generate_before_main_content', "type" => 'textarea' ), array( "name" => __( 'Before Content', 'gp-premium' ), "id" => 'generate_before_content', "type" => 'textarea' ), array( "name" => __( 'After Entry Title', 'gp-premium' ), "id" => 'generate_after_entry_header', "type" => 'textarea' ), array( "name" => __( 'After Content', 'gp-premium' ), "id" => 'generate_after_content', "type" => 'textarea' ), array( "name" => __( 'Before Right Sidebar Content', 'gp-premium' ), "id" => 'generate_before_right_sidebar_content', "type" => 'textarea' ), array( "name" => __( 'After Right Sidebar Content', 'gp-premium' ), "id" => 'generate_after_right_sidebar_content', "type" => 'textarea' ), array( "name" => __( 'Before Left Sidebar Content', 'gp-premium' ), "id" => 'generate_before_left_sidebar_content', "type" => 'textarea' ), array( "name" => __( 'After Left Sidebar Content', 'gp-premium' ), "id" => 'generate_after_left_sidebar_content', "type" => 'textarea' ), array( "name" => __( 'Before Footer', 'gp-premium' ), "id" => 'generate_before_footer', "type" => 'textarea' ), array( "name" => __( 'After Footer Widgets', 'gp-premium' ), "id" => 'generate_after_footer_widgets', "type" => 'textarea' ), array( "name" => __( 'Before Footer Content', 'gp-premium' ), "id" => 'generate_before_footer_content', "type" => 'textarea' ), array( "name" => __( 'After Footer Content', 'gp-premium' ), "id" => 'generate_after_footer_content', "type" => 'textarea' ), array( "name" => __( 'wp_footer', 'gp-premium' ), "id" => 'generate_wp_footer', "type" => 'textarea' ) ) ); $settings = apply_filters( 'gp_hooks_settings_fields', $settings ); return $settings; } /** * Register plugin settings * @return void */ public function register_settings() { if ( is_array( $this->settings ) ) { foreach( $this->settings as $section => $data ) { // Add section to page add_settings_section( $section, $data['title'], array( $this, 'settings_section' ), 'gp_hooks_settings' ); foreach( $data['fields'] as $field ) { // Sanitizing isn't possible, as hooks allow any HTML, JS or PHP to be added. // Allowing PHP can be a security issue if you have admin users who you don't trust. // In that case, you can disable the ability to add PHP in hooks like this: define( 'GENERATE_HOOKS_DISALLOW_PHP', true ); $validation = ''; if( isset( $field['callback'] ) ) { $validation = $field['callback']; } // Register field $option_name = $this->settings_base . $field['id']; register_setting( 'gp_hooks_settings', 'generate_hooks', $validation ); // Add field to page add_settings_field( 'generate_hooks[' . $field['id'] . ']', $field['name'], array( $this, 'display_field' ), 'gp_hooks_settings', $section, array( 'field' => $field ) ); } } } } public function settings_section( $section ) { $html = ''; echo $html; } /** * Generate HTML for displaying fields * @param array $args Field data * @return void */ public function display_field( $args ) { $field = $args['field']; $html = ''; $option_name = $this->settings_base . $field['id']; $option = get_option( 'generate_hooks' ); $data = ''; if( isset( $option[$option_name] ) ) { $data = $option[$option_name]; } elseif( isset( $field['default'] ) ) { $data = $field['default']; } switch( $field['type'] ) { case 'textarea': $checked = ''; $checked2 = ''; if( isset( $option[$field['id'] . '_php'] ) && 'true' == $option[$field['id'] . '_php'] ){ $checked = 'checked="checked"'; } if( isset( $option[$field['id'] . '_disable'] ) && 'true' == $option[$field['id'] . '_disable'] ){ $checked2 = 'checked="checked"'; } $html .= ''; if ( ! defined( 'GENERATE_HOOKS_DISALLOW_PHP' ) ) { $html .= '