class-email-encoder-bundle-ajax.php
6 years ago
class-email-encoder-bundle-helpers.php
6 years ago
class-email-encoder-bundle-run-admin.php
6 years ago
class-email-encoder-bundle-run.php
6 years ago
class-email-encoder-bundle-settings.php
6 years ago
class-email-encoder-bundle-validate.php
6 years ago
index.php
6 years ago
class-email-encoder-bundle-run-admin.php
251 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class Email_Encoder_Run |
| 5 | * |
| 6 | * Thats where we bring the plugin to life |
| 7 | * |
| 8 | * @since 2.0.0 |
| 9 | * @package EEB |
| 10 | * @author Ironikus <info@ironikus.com> |
| 11 | */ |
| 12 | |
| 13 | class Email_Encoder_Run{ |
| 14 | |
| 15 | /** |
| 16 | * The main page name for our admin page |
| 17 | * |
| 18 | * @var string |
| 19 | * @since 2.0.0 |
| 20 | */ |
| 21 | private $page_name; |
| 22 | |
| 23 | /** |
| 24 | * The main page title for our admin page |
| 25 | * |
| 26 | * @var string |
| 27 | * @since 2.0.0 |
| 28 | */ |
| 29 | private $page_title; |
| 30 | |
| 31 | /** |
| 32 | * The page hook itself for registering the meta boxes |
| 33 | * |
| 34 | * @var string |
| 35 | * @since 2.0.0 |
| 36 | */ |
| 37 | private $pagehook; |
| 38 | |
| 39 | /** |
| 40 | * Our Email_Encoder_Run constructor. |
| 41 | */ |
| 42 | function __construct(){ |
| 43 | $this->page_name = EEB()->settings->get_page_name(); |
| 44 | $this->page_title = EEB()->settings->get_page_title(); |
| 45 | $this->settings_key = EEB()->settings->get_settings_key(); |
| 46 | $this->display_notices = array(); |
| 47 | $this->add_hooks(); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Define all of our necessary hooks |
| 52 | */ |
| 53 | private function add_hooks(){ |
| 54 | |
| 55 | add_action( 'plugin_action_links_' . EEB_PLUGIN_BASE, array($this, 'plugin_action_links') ); |
| 56 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts_and_styles' ) ); |
| 57 | add_action( 'admin_menu', array( $this, 'add_user_submenu' ), 150 ); |
| 58 | add_action( 'admin_init', array( $this, 'save_settings' ), 10 ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Plugin action links. |
| 63 | * |
| 64 | * Adds action links to the plugin list table |
| 65 | * |
| 66 | * Fired by `plugin_action_links` filter. |
| 67 | * |
| 68 | * @since 2.0.0 |
| 69 | * @access public |
| 70 | * |
| 71 | * @param array $links An array of plugin action links. |
| 72 | * |
| 73 | * @return array An array of plugin action links. |
| 74 | */ |
| 75 | public function plugin_action_links( $links ) { |
| 76 | $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=' . $this->page_name ), __( 'Settings', 'email-encoder-bundle' ) ); |
| 77 | |
| 78 | array_unshift( $links, $settings_link ); |
| 79 | |
| 80 | $links['visit_us'] = sprintf( '<a href="%s" target="_blank" style="font-weight:700;color:#f1592a;">%s</a>', 'https://ironikus.com/?utm_source=email-encoder-bundle&utm_medium=plugin-overview-website-button&utm_campaign=WP%20Mailto%20Links', __('Visit us', 'email-encoder-bundle') ); |
| 81 | |
| 82 | return $links; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * ###################### |
| 87 | * ### |
| 88 | * #### SCRIPTS & STYLES |
| 89 | * ### |
| 90 | * ###################### |
| 91 | */ |
| 92 | |
| 93 | /** |
| 94 | * Register all necessary scripts and styles |
| 95 | * |
| 96 | * @since 2.0.0 |
| 97 | */ |
| 98 | public function enqueue_scripts_and_styles() { |
| 99 | if( EEB()->helpers->is_page( $this->page_name ) ) { |
| 100 | $js_version = date( "ymd-Gis", filemtime( EEB_PLUGIN_DIR . 'core/includes/assets/js/custom-admin.js' )); |
| 101 | $css_version = date( "ymd-Gis", filemtime( EEB_PLUGIN_DIR . 'core/includes/assets/css/style-admin.css' )); |
| 102 | |
| 103 | wp_enqueue_script( 'eeb-admin-scripts', EEB_PLUGIN_URL . 'core/includes/assets/js/custom-admin.js', array( 'jquery' ), $js_version, true ); |
| 104 | wp_register_style( 'eeb-css-backend', EEB_PLUGIN_URL . 'core/includes/assets/css/style-admin.css', false, $css_version ); |
| 105 | wp_enqueue_style ( 'eeb-css-backend' ); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * ###################### |
| 111 | * ### |
| 112 | * #### MENU TEMPLATE ITEMS |
| 113 | * ### |
| 114 | * ###################### |
| 115 | */ |
| 116 | |
| 117 | /** |
| 118 | * Add our custom admin user page |
| 119 | */ |
| 120 | public function add_user_submenu(){ |
| 121 | |
| 122 | if( (string) EEB()->settings->get_setting( 'own_admin_menu', true ) !== '1' ){ |
| 123 | $this->pagehook = add_submenu_page( 'options-general.php', __( $this->page_title, 'email-encoder-bundle' ), __( $this->page_title, 'email-encoder-bundle' ), EEB()->settings->get_admin_cap( 'admin-add-submenu-page-item' ), $this->page_name, array( $this, 'render_admin_menu_page' ) ); |
| 124 | } else { |
| 125 | $this->pagehook = add_menu_page( __( $this->page_title, 'email-encoder-bundle' ), __( $this->page_title, 'email-encoder-bundle' ), EEB()->settings->get_admin_cap( 'admin-add-menu-page-item' ), $this->page_name, array( $this, 'render_admin_menu_page' ), plugins_url( 'core/includes/assets/img/icon-email-encoder-bundle.png', EEB_PLUGIN_FILE ) ); |
| 126 | } |
| 127 | |
| 128 | add_action( 'load-' . $this->pagehook, array( $this, 'add_help_tabs' ) ); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Render the admin submenu page |
| 133 | * |
| 134 | * You need the specified capability to edit it. |
| 135 | */ |
| 136 | public function render_admin_menu_page(){ |
| 137 | if( ! current_user_can( EEB()->settings->get_admin_cap('admin-menu-page') ) ){ |
| 138 | wp_die( __( EEB()->settings->get_default_string( 'insufficient-permissions' ), 'email-encoder-bundle' ) ); |
| 139 | } |
| 140 | |
| 141 | include( EEB_PLUGIN_DIR . 'core/includes/partials/eeb-page-display.php' ); |
| 142 | |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * ###################### |
| 147 | * ### |
| 148 | * #### SETTINGS LOGIC |
| 149 | * ### |
| 150 | * ###################### |
| 151 | */ |
| 152 | |
| 153 | public function save_settings(){ |
| 154 | |
| 155 | if( isset( $_POST[ $this->page_name . '_nonce' ] ) ){ |
| 156 | if( ! wp_verify_nonce( $_POST[ $this->page_name . '_nonce' ], $this->page_name ) ){ |
| 157 | wp_die( __( 'You don\'t have permission to update these settings.', 'email-encoder-bundle' ) ); |
| 158 | } |
| 159 | |
| 160 | if( ! current_user_can( EEB()->settings->get_admin_cap( 'admin-update-settings' ) ) ){ |
| 161 | wp_die( __( 'You don\'t have permission to update these settings.', 'email-encoder-bundle' ) ); |
| 162 | } |
| 163 | |
| 164 | if( isset( $_POST[ $this->settings_key ] ) && is_array( $_POST[ $this->settings_key ] ) ){ |
| 165 | $check = update_option( $this->settings_key, $_POST[ $this->settings_key ] ); |
| 166 | if( $check ){ |
| 167 | EEB()->settings->reload_settings(); |
| 168 | $update_notice = EEB()->helpers->create_admin_notice( 'Settings successfully saved.', 'success', true ); |
| 169 | $this->display_notices[] = $update_notice; |
| 170 | } else { |
| 171 | $update_notice = EEB()->helpers->create_admin_notice( 'No changes were made to your settings with your last save.', 'info', true ); |
| 172 | $this->display_notices[] = $update_notice; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | } |
| 177 | |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * ###################### |
| 182 | * ### |
| 183 | * #### HELP TABS TEMPLATE ITEMS |
| 184 | * ### |
| 185 | * ###################### |
| 186 | */ |
| 187 | public function add_help_tabs(){ |
| 188 | $screen = get_current_screen(); |
| 189 | $display_encoder_form = (bool) EEB()->settings->get_setting( 'display_encoder_form', true, 'encoder_form' ); |
| 190 | |
| 191 | $defaults = array( |
| 192 | 'content' => '', |
| 193 | 'callback' => array( $this, 'load_help_tabs' ), |
| 194 | ); |
| 195 | |
| 196 | $screen->add_help_tab(wp_parse_args(array( |
| 197 | 'id' => 'general', |
| 198 | 'title' => __('General', 'email-encoder-bundle'), |
| 199 | ), $defaults)); |
| 200 | |
| 201 | $screen->add_help_tab(wp_parse_args(array( |
| 202 | 'id' => 'shortcodes', |
| 203 | 'title' => __('Shortcode', 'email-encoder-bundle'), |
| 204 | ), $defaults)); |
| 205 | |
| 206 | $screen->add_help_tab(wp_parse_args(array( |
| 207 | 'id' => 'template-tags', |
| 208 | 'title' => __('Template Tags', 'email-encoder-bundle'), |
| 209 | ), $defaults)); |
| 210 | |
| 211 | //Add widgets |
| 212 | if( $display_encoder_form ){ |
| 213 | add_meta_box( 'encode_form', __( $this->page_title, 'email-encoder-bundle' ), array( $this, 'show_meta_box_content' ), null, 'normal', 'core', array( 'encode_form' ) ); |
| 214 | } |
| 215 | |
| 216 | } |
| 217 | |
| 218 | public function load_help_tabs($screen, array $args){ |
| 219 | |
| 220 | if( ! empty( $args['id'] ) ){ |
| 221 | include( EEB_PLUGIN_DIR . 'core/includes/partials/help-tabs/' . $args['id'] . '.php' ); |
| 222 | } |
| 223 | |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Show content of metabox (callback) |
| 228 | * @param array $post |
| 229 | * @param array $meta_box |
| 230 | */ |
| 231 | public function show_meta_box_content( $post, $meta_box ) { |
| 232 | $key = $meta_box['args'][0]; |
| 233 | |
| 234 | if ($key === 'encode_form') { |
| 235 | ?> |
| 236 | <p><?php _e('If you like you can also create you own secured emails manually with this form. Just copy/paste the generated code and put it in your post, page or template. We choose automatically the best method for you, based on your settings.', 'email-encoder-bundle') ?></p> |
| 237 | |
| 238 | <hr style="border:1px solid #FFF; border-top:1px solid #EEE;" /> |
| 239 | |
| 240 | <?php echo EEB()->validate->get_encoder_form(); ?> |
| 241 | |
| 242 | <hr style="border:1px solid #FFF; border-top:1px solid #EEE;"/> |
| 243 | |
| 244 | <p class="description"><?php _e('You can also put the encoder form on your site by using the shortcode <code>[eeb_form]</code> or the template function <code>eeb_form()</code>.', 'email-encoder-bundle') ?></p> |
| 245 | <?php |
| 246 | } |
| 247 | |
| 248 | } |
| 249 | |
| 250 | } |
| 251 |