| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
class FrmAppController { |
| 7 |
|
| 8 |
public static function menu() { |
| 9 |
FrmAppHelper::maybe_add_permissions(); |
| 10 |
if ( ! current_user_can( 'frm_view_forms' ) ) { |
| 11 |
return; |
| 12 |
} |
| 13 |
|
| 14 |
$menu_name = FrmAppHelper::get_menu_name(); |
| 15 |
add_menu_page( 'Formidable', $menu_name, 'frm_view_forms', 'formidable', 'FrmFormsController::route', self::menu_icon(), self::get_menu_position() ); |
| 16 |
} |
| 17 |
|
| 18 |
private static function get_menu_position() { |
| 19 |
return apply_filters( 'frm_menu_position', '29.3' ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* @since 3.05 |
| 24 |
*/ |
| 25 |
private static function menu_icon() { |
| 26 |
$icon = FrmAppHelper::svg_logo( |
| 27 |
array( |
| 28 |
'fill' => '#a0a5aa', |
| 29 |
'orange' => '#a0a5aa', |
| 30 |
) |
| 31 |
); |
| 32 |
$icon = 'data:image/svg+xml;base64,' . base64_encode( $icon ); |
| 33 |
|
| 34 |
return apply_filters( 'frm_icon', $icon ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* @since 3.0 |
| 39 |
*/ |
| 40 |
public static function add_admin_class( $classes ) { |
| 41 |
if ( self::is_white_page() ) { |
| 42 |
$classes .= ' frm-white-body '; |
| 43 |
$classes .= self::get_os(); |
| 44 |
|
| 45 |
$page = str_replace( 'formidable-', '', FrmAppHelper::simple_get( 'page', 'sanitize_title' ) ); |
| 46 |
if ( empty( $page ) || $page === 'formidable' ) { |
| 47 |
$action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
| 48 |
if ( in_array( $action, array( 'settings', 'edit', 'list' ) ) ) { |
| 49 |
$page .= $action; |
| 50 |
} else { |
| 51 |
$page = $action; |
| 52 |
} |
| 53 |
} |
| 54 |
if ( ! empty( $page ) ) { |
| 55 |
$classes .= ' frm-admin-page-' . $page; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
if ( FrmAppHelper::is_full_screen() ) { |
| 60 |
$classes .= apply_filters( 'frm_admin_full_screen_class', ' frm-full-screen folded' ); |
| 61 |
} |
| 62 |
|
| 63 |
return $classes; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* @since 4.0 |
| 68 |
*/ |
| 69 |
private static function get_os() { |
| 70 |
$agent = strtolower( FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ) ); |
| 71 |
$os = ''; |
| 72 |
if ( strpos( $agent, 'mac' ) !== false ) { |
| 73 |
$os = ' osx'; |
| 74 |
} elseif ( strpos( $agent, 'linux' ) !== false ) { |
| 75 |
$os = ' linux'; |
| 76 |
} elseif ( strpos( $agent, 'windows' ) !== false ) { |
| 77 |
$os = ' windows'; |
| 78 |
} |
| 79 |
return $os; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* @since 3.0 |
| 84 |
*/ |
| 85 |
private static function is_white_page() { |
| 86 |
$white_pages = array( |
| 87 |
'formidable', |
| 88 |
'formidable-entries', |
| 89 |
'formidable-views', |
| 90 |
'formidable-pro-upgrade', |
| 91 |
'formidable-addons', |
| 92 |
'formidable-import', |
| 93 |
'formidable-settings', |
| 94 |
'formidable-styles', |
| 95 |
'formidable-styles2', |
| 96 |
'formidable-inbox', |
| 97 |
'formidable-welcome', |
| 98 |
); |
| 99 |
|
| 100 |
$get_page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); |
| 101 |
$is_white_page = in_array( $get_page, $white_pages ); |
| 102 |
|
| 103 |
if ( ! $is_white_page ) { |
| 104 |
$screen = get_current_screen(); |
| 105 |
$is_white_page = ( $screen && strpos( $screen->id, 'frm_display' ) !== false ); |
| 106 |
} |
| 107 |
|
| 108 |
return $is_white_page; |
| 109 |
} |
| 110 |
|
| 111 |
public static function load_wp_admin_style() { |
| 112 |
FrmAppHelper::load_font_style(); |
| 113 |
} |
| 114 |
|
| 115 |
public static function get_form_nav( $form, $show_nav = false, $title = 'show' ) { |
| 116 |
$show_nav = FrmAppHelper::get_param( 'show_nav', $show_nav, 'get', 'absint' ); |
| 117 |
if ( empty( $show_nav ) || ! $form ) { |
| 118 |
return; |
| 119 |
} |
| 120 |
|
| 121 |
FrmForm::maybe_get_form( $form ); |
| 122 |
if ( ! is_object( $form ) ) { |
| 123 |
return; |
| 124 |
} |
| 125 |
|
| 126 |
$id = $form->id; |
| 127 |
$current_page = self::get_current_page(); |
| 128 |
$nav_items = self::get_form_nav_items( $form ); |
| 129 |
|
| 130 |
include( FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php' ); |
| 131 |
} |
| 132 |
|
| 133 |
private static function get_current_page() { |
| 134 |
$page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); |
| 135 |
$post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title', 'None' ); |
| 136 |
$current_page = isset( $_GET['page'] ) ? $page : $post_type; |
| 137 |
|
| 138 |
if ( FrmAppHelper::is_view_builder_page() ) { |
| 139 |
$current_page = 'frm_display'; |
| 140 |
} |
| 141 |
|
| 142 |
return $current_page; |
| 143 |
} |
| 144 |
|
| 145 |
private static function get_form_nav_items( $form ) { |
| 146 |
$id = $form->parent_form_id ? $form->parent_form_id : $form->id; |
| 147 |
|
| 148 |
$nav_items = array( |
| 149 |
array( |
| 150 |
'link' => FrmForm::get_edit_link( $id ), |
| 151 |
'label' => __( 'Build', 'formidable' ), |
| 152 |
'current' => array( 'edit', 'new', 'duplicate' ), |
| 153 |
'page' => 'formidable', |
| 154 |
'permission' => 'frm_edit_forms', |
| 155 |
), |
| 156 |
array( |
| 157 |
'link' => admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . absint( $id ) ), |
| 158 |
'label' => __( 'Settings', 'formidable' ), |
| 159 |
'current' => array( 'settings' ), |
| 160 |
'page' => 'formidable', |
| 161 |
'permission' => 'frm_edit_forms', |
| 162 |
), |
| 163 |
array( |
| 164 |
'link' => admin_url( 'admin.php?page=formidable-entries&frm-full=1&frm_action=list&form=' . absint( $id ) ), |
| 165 |
'label' => __( 'Entries', 'formidable' ), |
| 166 |
'current' => array(), |
| 167 |
'page' => 'formidable-entries', |
| 168 |
'permission' => 'frm_view_entries', |
| 169 |
), |
| 170 |
); |
| 171 |
|
| 172 |
$views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) ? FrmProAppHelper::views_is_installed() : FrmAppHelper::pro_is_installed(); |
| 173 |
|
| 174 |
if ( ! $views_installed ) { |
| 175 |
$nav_items[] = array( |
| 176 |
'link' => admin_url( 'admin.php?page=formidable-views&frm-full=1&form=' . absint( $id ) ), |
| 177 |
'label' => __( 'Views', 'formidable' ), |
| 178 |
'current' => array(), |
| 179 |
'page' => 'formidable-views', |
| 180 |
'permission' => 'frm_view_entries', |
| 181 |
'atts' => array( |
| 182 |
'class' => 'frm_noallow', |
| 183 |
), |
| 184 |
); |
| 185 |
} |
| 186 |
|
| 187 |
// Let people know reports and views exist. |
| 188 |
if ( ! FrmAppHelper::pro_is_installed() ) { |
| 189 |
$nav_items[] = array( |
| 190 |
'link' => admin_url( 'admin.php?page=formidable&frm_action=lite-reports&frm-full=1&form=' . absint( $id ) ), |
| 191 |
'label' => __( 'Reports', 'formidable' ), |
| 192 |
'current' => array( 'reports' ), |
| 193 |
'page' => 'formidable', |
| 194 |
'permission' => 'frm_view_entries', |
| 195 |
'atts' => array( |
| 196 |
'class' => 'frm_noallow', |
| 197 |
), |
| 198 |
); |
| 199 |
} |
| 200 |
|
| 201 |
$nav_args = array( |
| 202 |
'form_id' => $id, |
| 203 |
'form' => $form, |
| 204 |
); |
| 205 |
|
| 206 |
return apply_filters( 'frm_form_nav_list', $nav_items, $nav_args ); |
| 207 |
} |
| 208 |
|
| 209 |
// Adds a settings link to the plugins page |
| 210 |
public static function settings_link( $links ) { |
| 211 |
$settings = array(); |
| 212 |
|
| 213 |
if ( ! FrmAppHelper::pro_is_installed() ) { |
| 214 |
$settings[] = '<a href="' . esc_url( FrmAppHelper::admin_upgrade_link( 'plugin-row' ) ) . '" target="_blank" rel="noopener"><b>' . esc_html__( 'Upgrade to Pro', 'formidable' ) . '</b></a>'; |
| 215 |
} |
| 216 |
|
| 217 |
$settings[] = '<a href="' . esc_url( admin_url( 'admin.php?page=formidable' ) ) . '">' . __( 'Build a Form', 'formidable' ) . '</a>'; |
| 218 |
|
| 219 |
return array_merge( $settings, $links ); |
| 220 |
} |
| 221 |
|
| 222 |
public static function pro_get_started_headline() { |
| 223 |
self::review_request(); |
| 224 |
FrmAppHelper::min_pro_version_notice( '4.0' ); |
| 225 |
} |
| 226 |
|
| 227 |
/** |
| 228 |
* Add admin notices as needed for reviews |
| 229 |
* |
| 230 |
* @since 3.04.03 |
| 231 |
*/ |
| 232 |
private static function review_request() { |
| 233 |
$reviews = new FrmReviews(); |
| 234 |
$reviews->review_request(); |
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* Save the request to hide the review |
| 239 |
* |
| 240 |
* @since 3.04.03 |
| 241 |
*/ |
| 242 |
public static function dismiss_review() { |
| 243 |
FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 244 |
check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 245 |
|
| 246 |
$reviews = new FrmReviews(); |
| 247 |
$reviews->dismiss_review(); |
| 248 |
} |
| 249 |
|
| 250 |
/** |
| 251 |
* @since 3.04.02 |
| 252 |
*/ |
| 253 |
public static function include_upgrade_overlay() { |
| 254 |
wp_enqueue_script( 'jquery-ui-dialog' ); |
| 255 |
wp_enqueue_style( 'jquery-ui-dialog' ); |
| 256 |
|
| 257 |
add_action( 'admin_footer', 'FrmAppController::upgrade_overlay_html' ); |
| 258 |
} |
| 259 |
|
| 260 |
/** |
| 261 |
* @since 3.06.03 |
| 262 |
*/ |
| 263 |
public static function upgrade_overlay_html() { |
| 264 |
$is_pro = FrmAppHelper::pro_is_installed(); |
| 265 |
$upgrade_link = array( |
| 266 |
'medium' => 'builder', |
| 267 |
'content' => 'upgrade', |
| 268 |
); |
| 269 |
$default_link = FrmAppHelper::admin_upgrade_link( $upgrade_link ); |
| 270 |
$plugin_path = FrmAppHelper::plugin_path(); |
| 271 |
$shared_path = $plugin_path . '/classes/views/shared/'; |
| 272 |
|
| 273 |
include $shared_path . 'upgrade_overlay.php'; |
| 274 |
include $shared_path . 'confirm-overlay.php'; |
| 275 |
|
| 276 |
if ( ( FrmAppHelper::is_admin_page( 'formidable' ) || FrmAppHelper::is_admin_page( 'formidable-welcome' ) ) && in_array( FrmAppHelper::get_param( 'frm_action' ), array( '', 'list', 'trash' ), true ) ) { |
| 277 |
self::new_form_overlay_html(); |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
private static function new_form_overlay_html() { |
| 282 |
FrmFormsController::before_list_templates(); |
| 283 |
|
| 284 |
$plugin_path = FrmAppHelper::plugin_path(); |
| 285 |
$path = $plugin_path . '/classes/views/frm-forms/'; |
| 286 |
$expired = FrmFormsController::expired(); |
| 287 |
$expiring = FrmAddonsController::is_license_expiring(); |
| 288 |
$user = wp_get_current_user(); // $user used in leave-email.php to determine a default value for field |
| 289 |
$view_path = $path . 'new-form-overlay/'; |
| 290 |
$modal_class = ''; |
| 291 |
$upgrade_link = FrmAppHelper::admin_upgrade_link( |
| 292 |
array( |
| 293 |
'medium' => 'new-template', |
| 294 |
'content' => 'upgrade', |
| 295 |
) |
| 296 |
); |
| 297 |
$renew_link = FrmAppHelper::admin_upgrade_link( |
| 298 |
array( |
| 299 |
'medium' => 'new-template', |
| 300 |
'content' => 'renew', |
| 301 |
) |
| 302 |
); |
| 303 |
$blocks_to_render = array(); |
| 304 |
|
| 305 |
if ( ! FrmAppHelper::pro_is_installed() ) { |
| 306 |
// avoid rendering the email and code blocks for users who have upgraded or have a free license already |
| 307 |
$api = new FrmFormTemplateApi(); |
| 308 |
if ( ! $api->has_free_access() ) { |
| 309 |
array_push( $blocks_to_render, 'email', 'code' ); |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
// avoid rendering the upgrade block for users with elite |
| 314 |
if ( 'elite' !== FrmAddonsController::license_type() ) { |
| 315 |
$blocks_to_render[] = 'upgrade'; |
| 316 |
} |
| 317 |
|
| 318 |
// avoid rendering the renew block for users who are not currently expired |
| 319 |
if ( $expired ) { |
| 320 |
$blocks_to_render[] = 'renew'; |
| 321 |
$modal_class = 'frm-expired'; |
| 322 |
} elseif ( $expiring ) { |
| 323 |
$modal_class = 'frm-expiring'; |
| 324 |
} |
| 325 |
|
| 326 |
include $path . 'new-form-overlay.php'; |
| 327 |
} |
| 328 |
|
| 329 |
public static function include_info_overlay() { |
| 330 |
wp_enqueue_script( 'jquery-ui-dialog' ); |
| 331 |
wp_enqueue_style( 'jquery-ui-dialog' ); |
| 332 |
|
| 333 |
add_action( 'admin_footer', 'FrmAppController::info_overlay_html' ); |
| 334 |
} |
| 335 |
|
| 336 |
public static function info_overlay_html() { |
| 337 |
include( FrmAppHelper::plugin_path() . '/classes/views/shared/info-overlay.php' ); |
| 338 |
} |
| 339 |
|
| 340 |
/** |
| 341 |
* @since 3.04.02 |
| 342 |
*/ |
| 343 |
public static function remove_upsells() { |
| 344 |
remove_action( 'frm_before_settings', 'FrmSettingsController::license_box' ); |
| 345 |
remove_action( 'frm_after_settings', 'FrmSettingsController::settings_cta' ); |
| 346 |
remove_action( 'frm_add_form_style_tab_options', 'FrmFormsController::add_form_style_tab_options' ); |
| 347 |
remove_action( 'frm_after_field_options', 'FrmFormsController::logic_tip' ); |
| 348 |
|
| 349 |
if ( is_callable( 'FrmProAddonsController::renewal_message' ) ) { |
| 350 |
// These functions moved to Pro in 4.09.01 |
| 351 |
remove_action( 'frm_page_footer', 'FrmAppHelper::renewal_message' ); |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
/** |
| 356 |
* If there are CURL problems on this server, wp_remote_post won't work for installing |
| 357 |
* Use a javascript fallback instead. |
| 358 |
* |
| 359 |
* @since 2.0.3 |
| 360 |
*/ |
| 361 |
public static function install_js_fallback() { |
| 362 |
FrmAppHelper::load_admin_wide_js(); |
| 363 |
echo '<div id="hidden frm_install_message"></div><script type="text/javascript">jQuery(document).ready(function(){frm_install_now();});</script>'; |
| 364 |
} |
| 365 |
|
| 366 |
/** |
| 367 |
* Check if the database is outdated |
| 368 |
* |
| 369 |
* @since 2.0.1 |
| 370 |
* @return boolean |
| 371 |
*/ |
| 372 |
public static function needs_update() { |
| 373 |
$needs_upgrade = self::compare_for_update( |
| 374 |
array( |
| 375 |
'option' => 'frm_db_version', |
| 376 |
'new_db_version' => FrmAppHelper::$db_version, |
| 377 |
'new_plugin_version' => FrmAppHelper::plugin_version(), |
| 378 |
) |
| 379 |
); |
| 380 |
|
| 381 |
if ( ! $needs_upgrade ) { |
| 382 |
$needs_upgrade = apply_filters( 'frm_db_needs_upgrade', $needs_upgrade ); |
| 383 |
} |
| 384 |
|
| 385 |
return $needs_upgrade; |
| 386 |
} |
| 387 |
|
| 388 |
/** |
| 389 |
* Check both version number and DB number for changes |
| 390 |
* |
| 391 |
* @since 3.0.04 |
| 392 |
*/ |
| 393 |
public static function compare_for_update( $atts ) { |
| 394 |
$db_version = get_option( $atts['option'] ); |
| 395 |
|
| 396 |
if ( strpos( $db_version, '-' ) === false ) { |
| 397 |
$needs_upgrade = true; |
| 398 |
} else { |
| 399 |
$last_upgrade = explode( '-', $db_version ); |
| 400 |
$needs_db_upgrade = (int) $last_upgrade[1] < (int) $atts['new_db_version']; |
| 401 |
$new_version = version_compare( $last_upgrade[0], $atts['new_plugin_version'], '<' ); |
| 402 |
$needs_upgrade = $needs_db_upgrade || $new_version; |
| 403 |
} |
| 404 |
|
| 405 |
return $needs_upgrade; |
| 406 |
} |
| 407 |
|
| 408 |
/** |
| 409 |
* Check for database update and trigger js loading |
| 410 |
* |
| 411 |
* @since 2.0.1 |
| 412 |
*/ |
| 413 |
public static function admin_init() { |
| 414 |
new FrmPersonalData(); // register personal data hooks |
| 415 |
|
| 416 |
if ( ! FrmAppHelper::doing_ajax() && self::needs_update() ) { |
| 417 |
self::network_upgrade_site(); |
| 418 |
} |
| 419 |
|
| 420 |
if ( ! FrmAppHelper::doing_ajax() ) { |
| 421 |
// don't continue during ajax calls |
| 422 |
self::admin_js(); |
| 423 |
} |
| 424 |
|
| 425 |
if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
| 426 |
$action = FrmAppHelper::get_param( 'frm_action' ); |
| 427 |
|
| 428 |
if ( in_array( $action, array( 'add_new', 'list_templates' ), true ) ) { |
| 429 |
wp_safe_redirect( admin_url( 'admin.php?page=formidable&triggerNewFormModal=1' ) ); |
| 430 |
exit; |
| 431 |
} |
| 432 |
|
| 433 |
FrmInbox::maybe_disable_screen_options(); |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
public static function admin_js() { |
| 438 |
$version = FrmAppHelper::plugin_version(); |
| 439 |
FrmAppHelper::load_admin_wide_js(); |
| 440 |
|
| 441 |
$dependecies = array( |
| 442 |
'formidable_admin_global', |
| 443 |
'jquery', |
| 444 |
'jquery-ui-core', |
| 445 |
'jquery-ui-draggable', |
| 446 |
'jquery-ui-sortable', |
| 447 |
'bootstrap_tooltip', |
| 448 |
'bootstrap-multiselect', |
| 449 |
'wp-i18n', |
| 450 |
); |
| 451 |
|
| 452 |
if ( FrmAppHelper::is_admin_page( 'formidable-styles' ) || FrmAppHelper::is_admin_page( 'formidable-styles2' ) ) { |
| 453 |
$dependecies[] = 'wp-color-picker'; |
| 454 |
} |
| 455 |
|
| 456 |
wp_register_script( 'formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', $dependecies, $version, true ); |
| 457 |
wp_register_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css', array(), $version ); |
| 458 |
wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() . '/js/bootstrap.min.js', array( 'jquery' ), '3.3.4' ); |
| 459 |
wp_register_style( 'formidable-grids', FrmAppHelper::plugin_url() . '/css/frm_grids.css', array(), $version ); |
| 460 |
|
| 461 |
// load multselect js |
| 462 |
$depends_on = array( 'jquery', 'bootstrap_tooltip' ); |
| 463 |
wp_register_script( 'bootstrap-multiselect', FrmAppHelper::plugin_url() . '/js/bootstrap-multiselect.js', $depends_on, '0.9.8', true ); |
| 464 |
|
| 465 |
$page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); |
| 466 |
$post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' ); |
| 467 |
|
| 468 |
global $pagenow; |
| 469 |
if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow == 'edit.php' && $post_type == 'frm_display' ) ) { |
| 470 |
|
| 471 |
wp_enqueue_script( 'admin-widgets' ); |
| 472 |
wp_enqueue_style( 'widgets' ); |
| 473 |
wp_enqueue_script( 'formidable_admin' ); |
| 474 |
FrmAppHelper::localize_script( 'admin' ); |
| 475 |
|
| 476 |
wp_enqueue_style( 'formidable-admin' ); |
| 477 |
if ( 'formidable-styles' !== $page && 'formidable-styles2' !== $page ) { |
| 478 |
wp_enqueue_style( 'formidable-grids' ); |
| 479 |
wp_enqueue_style( 'formidable-dropzone' ); |
| 480 |
} else { |
| 481 |
wp_enqueue_style( 'formidable-grids' ); |
| 482 |
} |
| 483 |
|
| 484 |
if ( 'formidable-entries' === $page ) { |
| 485 |
// Load front end js for entries. |
| 486 |
wp_enqueue_script( 'formidable' ); |
| 487 |
} |
| 488 |
|
| 489 |
do_action( 'frm_enqueue_builder_scripts' ); |
| 490 |
self::include_upgrade_overlay(); |
| 491 |
self::include_info_overlay(); |
| 492 |
} elseif ( FrmAppHelper::is_view_builder_page() ) { |
| 493 |
if ( isset( $_REQUEST['post_type'] ) ) { |
| 494 |
$post_type = sanitize_title( wp_unslash( $_REQUEST['post_type'] ) ); |
| 495 |
} elseif ( isset( $_REQUEST['post'] ) && absint( $_REQUEST['post'] ) ) { |
| 496 |
$post = get_post( absint( wp_unslash( $_REQUEST['post'] ) ) ); |
| 497 |
if ( ! $post ) { |
| 498 |
return; |
| 499 |
} |
| 500 |
$post_type = $post->post_type; |
| 501 |
} else { |
| 502 |
return; |
| 503 |
} |
| 504 |
|
| 505 |
if ( $post_type == 'frm_display' ) { |
| 506 |
wp_enqueue_style( 'formidable-grids' ); |
| 507 |
wp_enqueue_script( 'jquery-ui-draggable' ); |
| 508 |
wp_enqueue_script( 'formidable_admin' ); |
| 509 |
wp_enqueue_style( 'formidable-admin' ); |
| 510 |
FrmAppHelper::localize_script( 'admin' ); |
| 511 |
self::include_info_overlay(); |
| 512 |
} |
| 513 |
} |
| 514 |
} |
| 515 |
|
| 516 |
public static function load_lang() { |
| 517 |
load_plugin_textdomain( 'formidable', false, FrmAppHelper::plugin_folder() . '/languages/' ); |
| 518 |
} |
| 519 |
|
| 520 |
/** |
| 521 |
* Check if the styles are updated when a form is loaded on the front-end |
| 522 |
* |
| 523 |
* @since 3.0.1 |
| 524 |
*/ |
| 525 |
public static function maybe_update_styles() { |
| 526 |
if ( self::needs_update() ) { |
| 527 |
self::network_upgrade_site(); |
| 528 |
} |
| 529 |
} |
| 530 |
|
| 531 |
/** |
| 532 |
* @since 3.0 |
| 533 |
*/ |
| 534 |
public static function create_rest_routes() { |
| 535 |
$args = array( |
| 536 |
'methods' => 'GET', |
| 537 |
'callback' => 'FrmAppController::api_install', |
| 538 |
'permission_callback' => __CLASS__ . '::can_update_db', |
| 539 |
); |
| 540 |
|
| 541 |
register_rest_route( 'frm-admin/v1', '/install', $args ); |
| 542 |
|
| 543 |
$args = array( |
| 544 |
'methods' => 'GET', |
| 545 |
'callback' => 'FrmAddonsController::install_addon_api', |
| 546 |
'permission_callback' => 'FrmAddonsController::can_install_addon_api', |
| 547 |
); |
| 548 |
|
| 549 |
register_rest_route( 'frm-admin/v1', '/install-addon', $args ); |
| 550 |
} |
| 551 |
|
| 552 |
/** |
| 553 |
* Make sure the install is only being run when we tell it to. |
| 554 |
* We don't want to run manually by people calling the API. |
| 555 |
* |
| 556 |
* @since 4.06.02 |
| 557 |
*/ |
| 558 |
public static function can_update_db() { |
| 559 |
return get_transient( 'frm_updating_api' ); |
| 560 |
} |
| 561 |
|
| 562 |
/** |
| 563 |
* Run silent upgrade on each site in the network during a network upgrade. |
| 564 |
* Update database settings for all sites in a network during network upgrade process. |
| 565 |
* |
| 566 |
* @since 2.0.1 |
| 567 |
* |
| 568 |
* @param int $blog_id Blog ID. |
| 569 |
*/ |
| 570 |
public static function network_upgrade_site( $blog_id = 0 ) { |
| 571 |
// Flag to check if install is happening as intended. |
| 572 |
set_transient( 'frm_updating_api', true, MINUTE_IN_SECONDS ); |
| 573 |
$request = new WP_REST_Request( 'GET', '/frm-admin/v1/install' ); |
| 574 |
|
| 575 |
self::maybe_add_wp_site_health(); |
| 576 |
|
| 577 |
if ( $blog_id ) { |
| 578 |
switch_to_blog( $blog_id ); |
| 579 |
$response = rest_do_request( $request ); |
| 580 |
restore_current_blog(); |
| 581 |
} else { |
| 582 |
$response = rest_do_request( $request ); |
| 583 |
} |
| 584 |
|
| 585 |
if ( $response->is_error() ) { |
| 586 |
// if the remove post fails, use javascript instead |
| 587 |
add_action( 'admin_notices', 'FrmAppController::install_js_fallback' ); |
| 588 |
} |
| 589 |
} |
| 590 |
|
| 591 |
/** |
| 592 |
* Make sure WP_Site_Health has been included because it is required when calling rest_do_request. |
| 593 |
* Check first that the file exists because WP_Site_Health was only introduced in WordPress 5.2. |
| 594 |
*/ |
| 595 |
private static function maybe_add_wp_site_health() { |
| 596 |
if ( ! class_exists( 'WP_Site_Health' ) ) { |
| 597 |
$wp_site_health_path = ABSPATH . 'wp-admin/includes/class-wp-site-health.php'; |
| 598 |
if ( file_exists( $wp_site_health_path ) ) { |
| 599 |
require_once $wp_site_health_path; |
| 600 |
} |
| 601 |
} |
| 602 |
} |
| 603 |
|
| 604 |
/** |
| 605 |
* @since 3.0 |
| 606 |
*/ |
| 607 |
public static function api_install() { |
| 608 |
delete_transient( 'frm_updating_api' ); |
| 609 |
if ( self::needs_update() ) { |
| 610 |
$running = get_option( 'frm_install_running' ); |
| 611 |
if ( false === $running || $running < strtotime( '-5 minutes' ) ) { |
| 612 |
update_option( 'frm_install_running', time(), 'no' ); |
| 613 |
self::install(); |
| 614 |
delete_option( 'frm_install_running' ); |
| 615 |
} |
| 616 |
} |
| 617 |
|
| 618 |
return true; |
| 619 |
} |
| 620 |
|
| 621 |
/** |
| 622 |
* Silent database upgrade (no redirect). |
| 623 |
* Called via ajax request during network upgrade process. |
| 624 |
* |
| 625 |
* @since 2.0.1 |
| 626 |
*/ |
| 627 |
public static function ajax_install() { |
| 628 |
self::api_install(); |
| 629 |
wp_die(); |
| 630 |
} |
| 631 |
|
| 632 |
public static function install() { |
| 633 |
$frmdb = new FrmMigrate(); |
| 634 |
$frmdb->upgrade(); |
| 635 |
} |
| 636 |
|
| 637 |
public static function uninstall() { |
| 638 |
FrmAppHelper::permission_check( 'administrator' ); |
| 639 |
check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 640 |
|
| 641 |
$frmdb = new FrmMigrate(); |
| 642 |
$frmdb->uninstall(); |
| 643 |
|
| 644 |
//disable the plugin and redirect after uninstall so the tables don't get added right back |
| 645 |
$plugins = array( FrmAppHelper::plugin_folder() . '/formidable.php', 'formidable-pro/formidable-pro.php' ); |
| 646 |
deactivate_plugins( $plugins, false, false ); |
| 647 |
echo esc_url_raw( admin_url( 'plugins.php?deactivate=true' ) ); |
| 648 |
|
| 649 |
wp_die(); |
| 650 |
} |
| 651 |
|
| 652 |
public static function drop_tables( $tables ) { |
| 653 |
global $wpdb; |
| 654 |
$tables[] = $wpdb->prefix . 'frm_fields'; |
| 655 |
$tables[] = $wpdb->prefix . 'frm_forms'; |
| 656 |
$tables[] = $wpdb->prefix . 'frm_items'; |
| 657 |
$tables[] = $wpdb->prefix . 'frm_item_metas'; |
| 658 |
|
| 659 |
return $tables; |
| 660 |
} |
| 661 |
|
| 662 |
public static function deauthorize() { |
| 663 |
FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 664 |
check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 665 |
|
| 666 |
delete_option( 'frmpro-credentials' ); |
| 667 |
delete_option( 'frmpro-authorized' ); |
| 668 |
delete_site_option( 'frmpro-credentials' ); |
| 669 |
delete_site_option( 'frmpro-authorized' ); |
| 670 |
wp_die(); |
| 671 |
} |
| 672 |
|
| 673 |
public static function set_footer_text( $text ) { |
| 674 |
if ( FrmAppHelper::is_formidable_admin() ) { |
| 675 |
$text = ''; |
| 676 |
} |
| 677 |
|
| 678 |
return $text; |
| 679 |
} |
| 680 |
|
| 681 |
/** |
| 682 |
* @deprecated 1.07.05 |
| 683 |
* @codeCoverageIgnore |
| 684 |
*/ |
| 685 |
public static function get_form_shortcode( $atts ) { |
| 686 |
return FrmDeprecated::get_form_shortcode( $atts ); |
| 687 |
} |
| 688 |
|
| 689 |
/** |
| 690 |
* @deprecated 2.5.4 |
| 691 |
* @codeCoverageIgnore |
| 692 |
*/ |
| 693 |
public static function widget_text_filter( $content ) { |
| 694 |
return FrmDeprecated::widget_text_filter( $content ); |
| 695 |
} |
| 696 |
|
| 697 |
/** |
| 698 |
* Deprecated in favor of wpmu_upgrade_site |
| 699 |
* |
| 700 |
* @deprecated 2.3 |
| 701 |
* @codeCoverageIgnore |
| 702 |
*/ |
| 703 |
public static function front_head() { |
| 704 |
FrmDeprecated::front_head(); |
| 705 |
} |
| 706 |
|
| 707 |
/** |
| 708 |
* @deprecated 3.0.04 |
| 709 |
* @codeCoverageIgnore |
| 710 |
*/ |
| 711 |
public static function activation_install() { |
| 712 |
FrmDeprecated::activation_install(); |
| 713 |
} |
| 714 |
|
| 715 |
/** |
| 716 |
* @deprecated 3.0 |
| 717 |
* @codeCoverageIgnore |
| 718 |
*/ |
| 719 |
public static function page_route( $content ) { |
| 720 |
return FrmDeprecated::page_route( $content ); |
| 721 |
} |
| 722 |
} |
| 723 |
|