| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin menus |
| 4 |
* |
| 5 |
* @package |
| 6 |
*/ |
| 7 |
namespace WPFunnels\Menu; |
| 8 |
|
| 9 |
use WPFunnels\Admin\SetupWizard; |
| 10 |
use WPFunnels\Wpfnl; |
| 11 |
use WPFunnels\Wpfnl_functions; |
| 12 |
|
| 13 |
/** |
| 14 |
* Class Wpfnl_Menus |
| 15 |
* |
| 16 |
* @package Wpfnl |
| 17 |
*/ |
| 18 |
class Wpfnl_Menus |
| 19 |
{ |
| 20 |
public function __construct() |
| 21 |
{ |
| 22 |
add_action('admin_menu', [$this, 'register_plugin_menus']); |
| 23 |
add_filter('admin_head', [$this, 'remove_submenu'], 10, 2); |
| 24 |
add_filter('admin_head', [$this, 'remove_notices_from_funnel_window'], 10, 2); |
| 25 |
add_action('admin_init', [$this, 'disallow_all_step_view']); |
| 26 |
add_action('admin_footer', [$this, 'doc_link_with_new_page']); |
| 27 |
|
| 28 |
if( isset($_GET['page']) && ( 'edit_funnel' === $_GET['page'] || 'wpfunnels_integrations' === $_GET['page'] ) ) { |
| 29 |
add_filter( "admin_body_class", array($this, 'add_folded_menu_class') ); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
/** |
| 35 |
* Register plugin menus and submenus |
| 36 |
* |
| 37 |
* @since 1.0.0 |
| 38 |
*/ |
| 39 |
public function register_plugin_menus() |
| 40 |
{ |
| 41 |
$role_permission = Wpfnl_functions::get_general_settings(); |
| 42 |
add_menu_page( |
| 43 |
__('WP Funnels', 'wpfnl'), |
| 44 |
__('WP Funnels', 'wpfnl'), |
| 45 |
Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ), |
| 46 |
WPFNL_MAIN_PAGE_SLUG, |
| 47 |
'', |
| 48 |
WPFNL_DIR_URL . 'admin/assets/images/funnel.svg', |
| 49 |
6 |
| 50 |
); |
| 51 |
|
| 52 |
add_submenu_page( |
| 53 |
WPFNL_MAIN_PAGE_SLUG, |
| 54 |
__('Funnels', 'wpfnl'), |
| 55 |
__('Funnels', 'wpfnl'), |
| 56 |
Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ), |
| 57 |
WPFNL_MAIN_PAGE_SLUG, |
| 58 |
[$this, 'render_funnels_page'] |
| 59 |
); |
| 60 |
|
| 61 |
add_submenu_page( |
| 62 |
WPFNL_MAIN_PAGE_SLUG, |
| 63 |
__('Settings', 'wpfnl'), |
| 64 |
__('Settings', 'wpfnl'), |
| 65 |
Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ), |
| 66 |
WPFNL_GLOBAL_SETTINGS_SLUG, |
| 67 |
[$this, 'render_settings_page'] |
| 68 |
); |
| 69 |
|
| 70 |
add_submenu_page( |
| 71 |
WPFNL_MAIN_PAGE_SLUG, |
| 72 |
__('Documentation', 'wpfnl'), |
| 73 |
'<span id="wpfnl-documentation">'. __('Documentation', 'wpfnl').'</span>', |
| 74 |
Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ), |
| 75 |
'https://getwpfunnels.com/resources/' |
| 76 |
); |
| 77 |
|
| 78 |
add_submenu_page( |
| 79 |
WPFNL_MAIN_PAGE_SLUG, |
| 80 |
__('Edit Funnel', 'wpfnl'), |
| 81 |
__('Edit Funnel', 'wpfnl'), |
| 82 |
Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ), |
| 83 |
WPFNL_EDIT_FUNNEL_SLUG, |
| 84 |
[$this, 'render_edit_funnel_page'] |
| 85 |
); |
| 86 |
|
| 87 |
add_submenu_page( |
| 88 |
WPFNL_MAIN_PAGE_SLUG, |
| 89 |
__('Request a Feature', 'wpfnl'), |
| 90 |
'<span id="wpfnl-request-feature">'. __('Request a Feature', 'wpfnl').'</span>', |
| 91 |
Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ), |
| 92 |
'https://getwpfunnels.com/ideas/' |
| 93 |
); |
| 94 |
|
| 95 |
add_submenu_page( |
| 96 |
WPFNL_MAIN_PAGE_SLUG, |
| 97 |
__('Email Builder', 'wpfnl'), |
| 98 |
__('Email Builder', 'wpfnl'), |
| 99 |
Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ), |
| 100 |
'email-builder', |
| 101 |
[$this, 'render_email_builder_page'] |
| 102 |
); |
| 103 |
|
| 104 |
|
| 105 |
do_action( 'wpfunnels/add_submenu'); |
| 106 |
|
| 107 |
if ( !Wpfnl_functions::is_wpfnl_pro_activated() ) { |
| 108 |
add_submenu_page( |
| 109 |
WPFNL_MAIN_PAGE_SLUG, |
| 110 |
__('Go Pro', 'wpfnl'), |
| 111 |
'<span class="dashicons dashicons-star-filled" style="font-size: 17px; color:#1fb3fb;"></span> ' . __('Go Pro', 'wpfnl'), |
| 112 |
Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ), |
| 113 |
'https://getwpfunnels.com/pricing/' |
| 114 |
); |
| 115 |
} elseif ( version_compare( WPFNL_PRO_VERSION, '1.2.9' , '<=' ) ) { |
| 116 |
/** |
| 117 |
* This will be removed in future, all license |
| 118 |
* related functionalities will be moved to pro |
| 119 |
*/ |
| 120 |
add_submenu_page( |
| 121 |
WPFNL_MAIN_PAGE_SLUG, |
| 122 |
__('License', 'wpfnl'), |
| 123 |
__('License', 'wpfnl'), |
| 124 |
Wpfnl_functions::role_permission_to_allow_wpfunnel( $role_permission ), |
| 125 |
'wpf-license', |
| 126 |
[$this, 'render_license'] |
| 127 |
); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
public function render_email_builder_page() { ?> |
| 133 |
<div id="email-builder"></div> |
| 134 |
<?php } |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
/** |
| 139 |
* Render funnel page |
| 140 |
* |
| 141 |
* @since 1.0.0 |
| 142 |
*/ |
| 143 |
public function render_funnels_page() |
| 144 |
{ |
| 145 |
Wpfnl::$instance->module_manager->get_admin_modules('funnels')->get_view(); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
/** |
| 150 |
* Render edit funnel page. |
| 151 |
* |
| 152 |
* @since 1.0.0 |
| 153 |
*/ |
| 154 |
public function render_edit_funnel_page() |
| 155 |
{ |
| 156 |
$funnel_id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_SPECIAL_CHARS); |
| 157 |
Wpfnl::$instance->module_manager->get_admin_modules('funnel')->init($funnel_id); |
| 158 |
Wpfnl::$instance->module_manager->get_admin_modules('funnel')->get_view(); |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* Render create funnel page |
| 163 |
* |
| 164 |
* @since 1.0.0 |
| 165 |
*/ |
| 166 |
public function render_create_funnel_page() |
| 167 |
{ |
| 168 |
Wpfnl::$instance->module_manager->get_admin_modules('create-funnel')->get_view(); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
/** |
| 173 |
* Render settings page |
| 174 |
* |
| 175 |
* @since 1.0.0 |
| 176 |
*/ |
| 177 |
public function render_settings_page() |
| 178 |
{ |
| 179 |
Wpfnl::$instance->module_manager->get_admin_modules('settings')->get_view(); |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
/** |
| 186 |
* Render license page for funnel |
| 187 |
* |
| 188 |
* @since 2.0.0 |
| 189 |
*/ |
| 190 |
public function render_license() { |
| 191 |
require WPFNL_DIR . '/admin/partials/license.php'; |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Remove submenu from plugin menu |
| 196 |
* |
| 197 |
* @since 1.0.0 |
| 198 |
*/ |
| 199 |
public function remove_submenu() |
| 200 |
{ |
| 201 |
remove_submenu_page(WPFNL_MAIN_PAGE_SLUG, 'edit_funnel'); |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
/** |
| 206 |
* Remove all notices from funnel window |
| 207 |
* |
| 208 |
* @since 2.0.0 |
| 209 |
*/ |
| 210 |
public function remove_notices_from_funnel_window() { |
| 211 |
if (empty($_GET['page'])) { |
| 212 |
return; |
| 213 |
} |
| 214 |
if (('edit_funnel' == sanitize_text_field( $_GET['page'] ) )) { |
| 215 |
remove_all_actions( 'admin_notices' ); |
| 216 |
} |
| 217 |
if ( 'wp_funnels' == sanitize_text_field( $_GET['page'] ) ) { |
| 218 |
add_action('admin_footer', array( $this, 'remove_admin_notices' )); |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
/** |
| 225 |
* Force user to visit all steps page |
| 226 |
* |
| 227 |
* @since 1.0.0 |
| 228 |
*/ |
| 229 |
public function disallow_all_step_view() |
| 230 |
{ |
| 231 |
global $pagenow; |
| 232 |
if ('edit.php' === $pagenow && isset($_GET['post_type']) && WPFNL_STEPS_POST_TYPE === sanitize_text_field($_GET['post_type'])) { |
| 233 |
$funnel_link = add_query_arg( |
| 234 |
[ |
| 235 |
'page' => WPFNL_MAIN_PAGE_SLUG, |
| 236 |
], |
| 237 |
admin_url('admin.php') |
| 238 |
); |
| 239 |
wp_safe_redirect( wp_sanitize_redirect( esc_url_raw( $funnel_link ) ) ); |
| 240 |
exit; |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
/** |
| 245 |
* Redirect user to pro url |
| 246 |
*/ |
| 247 |
public function redirect_to_pro() |
| 248 |
{ |
| 249 |
$url = 'https://getwpfunnels.com/pricing/'; |
| 250 |
wp_safe_redirect( wp_sanitize_redirect( esc_url_raw( $url ) ) ); |
| 251 |
exit(); |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
/** |
| 256 |
* Open with new page when documenation is clicked |
| 257 |
*/ |
| 258 |
public function doc_link_with_new_page(){ |
| 259 |
?> |
| 260 |
<script type="text/javascript"> |
| 261 |
jQuery(document).ready(function($) { |
| 262 |
$('#wpfnl-documentation').parent().attr('target','_blank'); |
| 263 |
$('#wpfnl-request-feature').parent().attr('target','_blank'); |
| 264 |
}); |
| 265 |
</script> |
| 266 |
<?php |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
public function add_folded_menu_class($classes) { |
| 271 |
return $classes." folded"; |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
/** |
| 276 |
* Remove admin notices |
| 277 |
*/ |
| 278 |
public function remove_admin_notices() { |
| 279 |
echo '<style>.update-nag, .updated, .error, .is-dismissible, .notice { display: none; } .wpfunnels-notice {display: block;}</style>'; |
| 280 |
} |
| 281 |
} |
| 282 |
|