From 66c38c52fb127a22edc7ab4eaafc542cccc342b9 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Mon, 17 Sep 2018 10:03:31 +0300 Subject: [PATCH] - changed installation process for UM core pages; - added notice after first install for set UM core pages; --- includes/admin/assets/js/um-admin-global.js | 4 + includes/admin/class-admin.php | 39 ++++++ includes/admin/core/class-admin-notices.php | 73 ++++++---- includes/core/class-setup.php | 144 ++++++++++---------- 4 files changed, 159 insertions(+), 101 deletions(-) diff --git a/includes/admin/assets/js/um-admin-global.js b/includes/admin/assets/js/um-admin-global.js index cdc76dd9..2121ec71 100644 --- a/includes/admin/assets/js/um-admin-global.js +++ b/includes/admin/assets/js/um-admin-global.js @@ -24,6 +24,10 @@ jQuery(document).ready(function() { }); + jQuery(document).on('click', '.um_secondary_dimiss', function (e) { + jQuery(this).parents('.um-admin-notice').find( '.notice-dismiss' ).trigger('click'); + }); + jQuery(document).on('click', '.um_opt_in_link', function (e) { jQuery(this).parents('.um-admin-notice').find( '.notice-dismiss' ).trigger('click'); }); diff --git a/includes/admin/class-admin.php b/includes/admin/class-admin.php index 230a33e5..8858efff 100644 --- a/includes/admin/class-admin.php +++ b/includes/admin/class-admin.php @@ -43,6 +43,8 @@ if ( ! class_exists( 'um\admin\Admin' ) ) { add_action( 'um_admin_do_action__um_hide_exif_notice', array( &$this, 'um_hide_notice' ) ); add_action( 'um_admin_do_action__user_action', array( &$this, 'user_action' ) ); + add_action( 'um_admin_do_action__install_core_pages', array( &$this, 'install_core_pages' ) ); + add_action( 'parent_file', array( &$this, 'parent_file' ), 9 ); add_filter( 'gettext', array( &$this, 'gettext' ), 10, 4 ); add_filter( 'post_updated_messages', array( &$this, 'post_updated_messages' ) ); @@ -83,6 +85,43 @@ if ( ! class_exists( 'um\admin\Admin' ) ) { } + /** + * Core pages installation + */ + function install_core_pages() { + if ( ! is_admin() ) { + die(); + } + + UM()->setup()->install_default_pages(); + + //check empty pages in settings + $empty_pages = array(); + + $pages = UM()->config()->permalinks; + if ( $pages && is_array( $pages ) ) { + foreach ( $pages as $slug => $page_id ) { + $page = get_post( $page_id ); + + if ( ! isset( $page->ID ) && in_array( $slug, array_keys( UM()->config()->core_pages ) ) ) { + $empty_pages[] = $slug; + } + } + } + + //if there aren't empty pages - then hide pages notice + if ( empty( $empty_pages ) ) { + $hidden_notices = get_option( 'um_hidden_admin_notices', array() ); + $hidden_notices[] = 'wrong_pages'; + + update_option( 'um_hidden_admin_notices', $hidden_notices ); + } + + $url = add_query_arg( array( 'page' => 'um_options' ), admin_url( 'admin.php' ) ); + exit( wp_redirect( $url ) ); + } + + /** * Clear all users cache * diff --git a/includes/admin/core/class-admin-notices.php b/includes/admin/core/class-admin-notices.php index 72f1a326..5f6c5aa6 100644 --- a/includes/admin/core/class-admin-notices.php +++ b/includes/admin/core/class-admin-notices.php @@ -36,7 +36,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) { function create_list() { $this->old_extensions_notice(); - $this->main_notices(); + $this->install_core_page_notice(); + $this->exif_extension_notice(); $this->localize_note(); $this->show_update_messages(); $this->check_wrong_install_folder(); @@ -46,7 +47,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) { $this->reviews_notice(); - //$this->future_changed(); /** @@ -283,40 +283,40 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) { /** - * Show main notices - */ - function main_notices() { - - $hide_exif_notice = get_option( 'um_hide_exif_notice' ); - - if ( ! extension_loaded( 'exif' ) && ! $hide_exif_notice ) { - $this->add_notice( 'exif_disabled', array( - 'class' => 'updated', - 'message' => '

' . sprintf(__( 'Exif is not enabled on your server. Mobile photo uploads will not be rotated correctly until you enable the exif extension. Hide this notice', 'ultimate-member' ), add_query_arg('um_adm_action', 'um_hide_exif_notice') ) . '

', - ), 10 ); - } - - // Regarding page setup + * Regarding page setup + */ + function install_core_page_notice() { $pages = UM()->config()->permalinks; + if ( $pages && is_array( $pages ) ) { - $err = false; - foreach ( $pages as $slug => $page_id ) { - $page = get_post( $page_id ); - if ( ! isset( $page->ID ) && in_array( $slug, array( 'user', 'account', 'members', 'register', 'login', 'logout', 'password-reset' ) ) ) { - $err = true; + if ( ! isset( $page->ID ) && in_array( $slug, array_keys( UM()->config()->core_pages ) ) ) { + + ob_start(); ?> + +

+ %s > Settings to re-assign your missing pages.', 'ultimate-member' ), ultimatemember_plugin_name, ultimatemember_plugin_name ); ?> +

+ +

+ +   + +

+ + add_notice( 'wrong_pages', array( + 'class' => 'updated', + 'message' => $message, + 'dismissible' => true + ), 20 ); + + break; } - - } - - if ( $err ) { - $this->add_notice( 'wrong_pages', array( - 'class' => 'updated', - 'message' => '

' . __( 'One or more of your Ultimate Member pages are not correctly setup. Please visit Ultimate Member > Settings to re-assign your missing pages.', 'ultimate-member' ) . '

', - ), 20 ); } if ( isset( $pages['user'] ) ) { @@ -343,6 +343,21 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) { } + /** + * EXIF library notice + */ + function exif_extension_notice() { + $hide_exif_notice = get_option( 'um_hide_exif_notice' ); + + if ( ! extension_loaded( 'exif' ) && ! $hide_exif_notice ) { + $this->add_notice( 'exif_disabled', array( + 'class' => 'updated', + 'message' => '

' . sprintf(__( 'Exif is not enabled on your server. Mobile photo uploads will not be rotated correctly until you enable the exif extension. Hide this notice', 'ultimate-member' ), add_query_arg('um_adm_action', 'um_hide_exif_notice') ) . '

', + ), 10 ); + } + } + + /** * Localization notice */ diff --git a/includes/core/class-setup.php b/includes/core/class-setup.php index 8d4aa6be..75dbb4bc 100644 --- a/includes/core/class-setup.php +++ b/includes/core/class-setup.php @@ -14,12 +14,6 @@ if ( ! class_exists( 'um\core\Setup' ) ) { class Setup { - /** - * @var array - */ - var $setup_shortcode = array(); - - /** * Setup constructor. */ @@ -34,6 +28,7 @@ if ( ! class_exists( 'um\core\Setup' ) ) { function run_setup() { $this->install_basics(); $this->install_default_forms(); + //$this->install_default_pages(); $this->set_default_settings(); $this->set_default_role_meta(); } @@ -43,8 +38,9 @@ if ( ! class_exists( 'um\core\Setup' ) ) { * Basics */ function install_basics() { - if ( ! get_option( '__ultimatemember_sitekey' ) ) + if ( ! get_option( '__ultimatemember_sitekey' ) ) { update_option( '__ultimatemember_sitekey', str_replace( array( 'http://', 'https://' ), '', sanitize_user( get_bloginfo('url') ) ) . '-' . wp_generate_password( 20, false ) ); + } } @@ -52,11 +48,8 @@ if ( ! class_exists( 'um\core\Setup' ) ) { * Default Forms */ function install_default_forms() { - - $options = get_option( 'um_options' ); - $options = empty( $options ) ? array() : $options; - if ( current_user_can( 'manage_options' ) && ! get_option( 'um_is_installed' ) ) { + $options = get_option( 'um_options', array() ); update_option( 'um_is_installed', 1 ); @@ -101,17 +94,14 @@ if ( ! class_exists( 'um\core\Setup' ) ) { } } - $this->setup_shortcode[$id] = '[ultimatemember form_id='.$form_id.']'; - - $core_forms[ $form_id ] = $form_id; - + $core_forms[ $id ] = $form_id; } /** DONE **/ - } - if ( isset( $core_forms ) ) + if ( isset( $core_forms ) ) { update_option( 'um_core_forms', $core_forms ); + } // Install Core Directories foreach ( UM()->config()->core_directories as $id ) { @@ -134,7 +124,7 @@ if ( ! class_exists( 'um\core\Setup' ) ) { $form_id = wp_insert_post( $form ); - foreach ( UM()->config()->core_directory_meta[$id] as $key => $value ) { + foreach ( UM()->config()->core_directory_meta[ $id ] as $key => $value ) { if ( $key == '_um_custom_fields' ) { $array = unserialize( $value ); update_post_meta( $form_id, $key, $array ); @@ -143,68 +133,78 @@ if ( ! class_exists( 'um\core\Setup' ) ) { } } - $this->setup_shortcode[$id] = '[ultimatemember form_id='.$form_id.']'; - - $core_directories[ $form_id ] = $form_id; - + $core_directories[ $id ] = $form_id; } /** DONE **/ } - if ( isset( $core_directories ) ) update_option( 'um_core_directories', $core_directories ); - - - // Install Core Pages - $core_pages = array(); - foreach ( UM()->config()->core_pages as $slug => $array ) { - - /** - If page does not exist - Create it - **/ - $page_exists = UM()->query()->find_post_id( 'page', '_um_core', $slug ); - if ( ! $page_exists ) { - - if ( $slug == 'logout' ) { - $content = ''; - } else if ( $slug == 'account' ) { - $content = '[ultimatemember_account]'; - } else if ( $slug == 'password-reset' ) { - $content = '[ultimatemember_password]'; - } else if ( $slug == 'user' ){ - $content = $this->setup_shortcode['profile']; - } else { - $content = $this->setup_shortcode[$slug]; - } - - $user_page = array( - 'post_title' => $array['title'], - 'post_content' => $content, - 'post_name' => $slug, - 'post_type' => 'post', - 'post_status' => 'publish', - 'post_author' => get_current_user_id(), - 'comment_status' => 'closed' - ); - - $post_id = wp_insert_post( $user_page ); - wp_update_post( array( 'ID' => $post_id, 'post_type' => 'page' ) ); - - update_post_meta( $post_id, '_um_core', $slug ); - - $core_pages[ $slug ] = $post_id; - - } else { - $core_pages[ $slug ] = $page_exists; - } - /** DONE **/ + if ( isset( $core_directories ) ) { + update_option( 'um_core_directories', $core_directories ); } - foreach ( $core_pages as $slug => $page_id ) { - $key = UM()->options()->get_core_page_id( $slug ); - $options[ $key ] = $page_id; + update_option( 'um_options', $options ); + } + } + + + /** + * Install Pre-defined pages with shortcodes + */ + function install_default_pages() { + if ( ! current_user_can( 'manage_options' ) ) { + return; + } + + $core_forms = get_option( 'um_core_forms', array() ); + $core_directories = get_option( 'um_core_directories', array() ); + + $setup_shortcodes = array_merge( $core_forms, $core_directories ); + + //Install Core Pages + $core_pages = array(); + foreach ( UM()->config()->core_pages as $slug => $array ) { + + $page_exists = UM()->query()->find_post_id( 'page', '_um_core', $slug ); + if ( $page_exists ) { + $core_pages[ $slug ] = $page_exists; + continue; } + + //If page does not exist - create it + if ( $slug == 'logout' ) { + $content = ''; + } elseif ( $slug == 'account' ) { + $content = '[ultimatemember_account]'; + } elseif ( $slug == 'password-reset' ) { + $content = '[ultimatemember_password]'; + } elseif ( $slug == 'user' ) { + $content = '[ultimatemember form_id="' . $setup_shortcodes['profile'] . '"]'; + } else { + $content = '[ultimatemember form_id="' . $setup_shortcodes[ $slug ] . '"]'; + } + + $user_page = array( + 'post_title' => $array['title'], + 'post_content' => $content, + 'post_name' => $slug, + 'post_type' => 'page', + 'post_status' => 'publish', + 'post_author' => get_current_user_id(), + 'comment_status' => 'closed' + ); + + $post_id = wp_insert_post( $user_page ); + update_post_meta( $post_id, '_um_core', $slug ); + + $core_pages[ $slug ] = $post_id; + } + + $options = get_option( 'um_options', array() ); + + foreach ( $core_pages as $slug => $page_id ) { + $key = UM()->options()->get_core_page_id( $slug ); + $options[ $key ] = $page_id; } update_option( 'um_options', $options );