get_branding_options();
$child_name = ( '' === $branding_opts['branding_preserve_title'] ) ? 'MainWP Child' : $branding_opts['branding_preserve_title'];
$dashboard_name = ( '' === $branding_opts['branding_preserve_title'] ) ? 'MainWP Dashboard' : $branding_opts['branding_preserve_title'] . ' Dashboard';
$msg = '
';
if ( ! MainWP_Child_Branding::instance()->is_branding() ) {
$msg .= '
';
$msg .= '

';
$msg .= '
';
}
$msg .= '
' . esc_html( $child_name ) . esc_html__( ' Plugin is Activated', 'mainwp-child' ) . '
';
$msg .= '
' . esc_html__( 'This site is now ready for connection. Please proceed with the connection process from your ', 'mainwp-child' ) . esc_html( $dashboard_name ) . ' ' . esc_html__( 'to start managing the site. ', 'mainwp-child' ) . '
';
$msg .= '
' . sprintf( esc_html__( 'If you need assistance, refer to our %1$sdocumentation%2$s.', 'mainwp-child' ), '
', '' ) . '
';
if ( ! MainWP_Child_Branding::instance()->is_branding() ) {
$msg .= '
' . esc_html__( 'For additional security options, visit the ', 'mainwp-child' ) . esc_html( $child_name ) . sprintf( esc_html__( ' %1$splugin settings%2$s. ', 'maiwnip-child' ), '
', '' ) . '
';
$msg .= '
';
}
$msg .= '
';
echo $msg; //phpcs:ignore -- NOSONAR - ok
}
if ( isset( $_GET['page'] ) && 'mainwp_child_tab' === $_GET['page'] && isset( $_GET['message'] ) ) { //phpcs:ignore -- ok.
$message = '';
if ( '1' === wp_unslash( $_GET['message'] ) ) { //phpcs:ignore -- ok.
$message = __( 'Disconnected the Site from Dashboard.', 'mainwp-child' );
} elseif ( '2' === wp_unslash( $_GET['message'] ) ) { //phpcs:ignore -- ok.
$message = __( 'Settings have been saved successfully.', 'mainwp-child' );
}
if ( ! empty( $message ) ) {
?>
delete_connection_data( false );
delete_option( 'mainwp_child_lasttime_not_connected' ); // reset.
wp_safe_redirect( 'options-general.php?page=mainwp_child_tab&message=1' );
}
// phpcs:disable WordPress.Security.NonceVerification
if ( isset( $_POST['submit'] ) && isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'child-settings' ) ) {
if ( isset( $_POST['requireUniqueSecurityId'] ) ) {
MainWP_Helper::update_option( 'mainwp_child_uniqueId', MainWP_Helper::rand_string( 12 ) );
} else {
MainWP_Helper::update_option( 'mainwp_child_uniqueId', '' );
}
MainWP_Helper::update_option( 'mainwp_child_ttl_active_unconnected_site', ! empty( $_POST['mainwp_child_active_time_for_unconnected_site'] ) ? intval( $_POST['mainwp_child_active_time_for_unconnected_site'] ) : 0 );
update_user_option( get_current_user_id(), 'mainwp_child_user_enable_passwd_auth_connect', ! empty( $_POST['mainwp_child_user_enable_pwd_auth_connect'] ) ? 1 : 0 );
wp_safe_redirect( 'options-general.php?page=mainwp_child_tab&message=2' );
}
// phpcs:enable
}
/**
* Add and remove Admin Menu Items dependant upon Branding settings.
*
* @uses \MainWP\Child\MainWP_Child_Branding::get_branding_options()
*/
public function admin_menu() { //phpcs:ignore -- NOSONAR - complex method.
$branding_opts = MainWP_Child_Branding::instance()->get_branding_options();
$is_hide = isset( $branding_opts['hide'] ) ? $branding_opts['hide'] : '';
$cancelled_branding = $branding_opts['cancelled_branding'];
$uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
if ( isset( $branding_opts['remove_wp_tools'] ) && $branding_opts['remove_wp_tools'] && ! $cancelled_branding ) {
remove_menu_page( 'tools.php' );
$pos = $uri ? stripos( $uri, 'tools.php' ) || stripos( $uri, 'import.php' ) || stripos( $uri, 'export.php' ) : false;
if ( false !== $pos ) {
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
}
}
// if preserve branding and do not remove menus.
if ( isset( $branding_opts['remove_wp_setting'] ) && $branding_opts['remove_wp_setting'] && ! $cancelled_branding ) {
remove_menu_page( 'options-general.php' );
$pos = $uri ? ( stripos( $uri, 'options-general.php' ) || stripos( $uri, 'options-writing.php' ) || stripos( $uri, 'options-reading.php' ) || stripos( $uri, 'options-discussion.php' ) || stripos( $uri, 'options-media.php' ) || stripos( $uri, 'options-permalink.php' ) ) : false;
if ( false !== $pos ) {
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
exit();
}
}
if ( isset( $branding_opts['remove_permalink'] ) && $branding_opts['remove_permalink'] && ! $cancelled_branding ) {
remove_submenu_page( 'options-general.php', 'options-permalink.php' );
$pos = $uri ? stripos( $uri, 'options-permalink.php' ) : false;
if ( false !== $pos ) {
wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
exit();
}
}
$remove_all_child_menu = false;
if ( isset( $branding_opts['remove_setting'] ) && isset( $branding_opts['remove_restore'] ) && isset( $branding_opts['remove_server_info'] ) && $branding_opts['remove_setting'] && $branding_opts['remove_restore'] && $branding_opts['remove_server_info'] ) {
$remove_all_child_menu = true;
}
// if preserve branding and do not hide menus.
if ( ( ! $remove_all_child_menu && 'T' !== $is_hide ) || $cancelled_branding ) {
$branding_header = isset( $branding_opts['branding_header'] ) ? $branding_opts['branding_header'] : array();
if ( ( is_array( $branding_header ) && ! empty( $branding_header['name'] ) ) && ! $cancelled_branding ) {
static::$brandingTitle = stripslashes( $branding_header['name'] );
$child_menu_title = stripslashes( $branding_header['name'] );
$child_page_title = $child_menu_title . ' Settings';
} else {
$child_menu_title = 'MainWP Child';
$child_page_title = 'MainWP Child Settings';
}
$this->init_pages( $child_menu_title, $child_page_title );
}
}
/**
* Initiate MainWP Child Plugin pages.
*
* @param string $child_menu_title New MainWP Child Plugin title defined in branding settings.
* @param string $child_page_title New MainWP Child Plugin page title defined in branding settings.
*
* @uses \MainWP\Child\MainWP_Clone_Page::get_class_name()
*/
private function init_pages( $child_menu_title, $child_page_title ) { //phpcs:ignore -- NOSONAR - complex.
$settingsPage = add_submenu_page( 'options-general.php', $child_page_title, $child_menu_title, 'manage_options', 'mainwp_child_tab', array( &$this, 'render_pages' ) );
add_action( 'admin_print_scripts-' . $settingsPage, array( MainWP_Clone_Page::get_class_name(), 'print_scripts' ) );
$sub_pages = array();
$all_subpages = apply_filters_deprecated( 'mainwp-child-init-subpages', array( array() ), '4.0.7.1', 'mainwp_child_init_subpages' ); // NOSONAR - no IP.
$all_subpages = apply_filters( 'mainwp_child_init_subpages', $all_subpages );
if ( ! is_array( $all_subpages ) ) {
$all_subpages = array();
}
if ( ! static::$subPagesLoaded ) {
foreach ( $all_subpages as $page ) {
$slug = isset( $page['slug'] ) ? $page['slug'] : '';
if ( empty( $slug ) ) {
continue;
}
$subpage = array();
$subpage['slug'] = $slug;
$subpage['title'] = $page['title'];
$subpage['page'] = 'mainwp-' . str_replace( ' ', '-', strtolower( str_replace( '-', ' ', $slug ) ) );
if ( isset( $page['callback'] ) ) {
$subpage['callback'] = $page['callback'];
$created_page = add_submenu_page( 'options-general.php', $subpage['title'], '
' . $subpage['title'] . '
', 'manage_options', $subpage['page'], $subpage['callback'] );
if ( isset( $page['load_callback'] ) ) {
$subpage['load_callback'] = $page['load_callback'];
add_action( 'load-' . $created_page, $subpage['load_callback'] );
}
}
$sub_pages[] = $subpage;
}
static::$subPages = $sub_pages;
static::$subPagesLoaded = true;
}
add_action( 'mainwp-child-pageheader', array( __CLASS__, 'render_header' ) );
add_action( 'mainwp-child-pagefooter', array( __CLASS__, 'render_footer' ) );
/**
* WordPress submenu array.
*
* @global array $submenu WordPress submenu array.
*/
global $submenu;
if ( isset( $submenu['options-general.php'] ) ) {
foreach ( $submenu['options-general.php'] as $index => $item ) {
if ( 'mainwp-reports-page' === $item[2] || 'mainwp-reports-settings' === $item[2] ) {
unset( $submenu['options-general.php'][ $index ] );
}
}
}
}
/**
* MainWP Child Plugin meta data.
*
* @param array $plugin_meta Plugin meta.
* @param string $plugin_file Plugin file.
*
* @return mixed The filtered value after all hooked functions are applied to it.
*/
public function plugin_row_meta( $plugin_meta, $plugin_file ) {
/**
* MainWP Child instance.
*
* @global object
*/
global $mainWPChild;
if ( ! $mainWPChild || $mainWPChild->plugin_slug !== $plugin_file ) {
return $plugin_meta;
}
return apply_filters( 'mainwp_child_plugin_row_meta', $plugin_meta, $plugin_file, $mainWPChild->plugin_slug );
}
/**
* Render MainWP Child Plugin pages.
*
* @uses \MainWP\Child\MainWP_Child_Branding::get_branding_options()
* @uses \MainWP\Child\MainWP_Child_Server_Information::render_page()
* @uses \MainWP\Child\MainWP_Child_Server_Information::render_connection_details()
* @uses \MainWP\Child\MainWP_Clone_Page::render()
* @uses \MainWP\Child\MainWP_Clone_Page::render_normal_restore()
* @uses \MainWP\Child\MainWP_Clone_Page::render_restore()
*/
public function render_pages() { // phpcs:ignore -- NOSONAR - Current complexity is the only way to achieve desired results, pull request solutions appreciated.
$shownPage = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
$branding_opts = MainWP_Child_Branding::instance()->get_branding_options();
$hide_settings = isset( $branding_opts['remove_setting'] ) && $branding_opts['remove_setting'] ? true : false;
$hide_restore = isset( $branding_opts['remove_restore'] ) && $branding_opts['remove_restore'] ? true : false;
$hide_server_info = isset( $branding_opts['remove_server_info'] ) && $branding_opts['remove_server_info'] ? true : false;
$hide_connection_detail = isset( $branding_opts['remove_connection_detail'] ) && $branding_opts['remove_connection_detail'] ? true : false;
if ( '' === $shownPage ) {
if ( ! $hide_settings ) {
$shownPage = 'settings';
} elseif ( ! $hide_restore ) {
$shownPage = 'restore-clone';
} elseif ( ! $hide_server_info ) {
$shownPage = 'server-info';
} elseif ( ! $hide_connection_detail ) {
$shownPage = 'connection-detail';
}
}
static::render_header( $shownPage, false, $show_clones );
if ( is_null( $show_clones ) ) {
$show_clones = true;
}
?>
>
render_settings(); ?>
>
>
>
get_branding_options();
$hide_settings = isset( $branding_opts['remove_setting'] ) && $branding_opts['remove_setting'] ? true : false;
$hide_restore = isset( $branding_opts['remove_restore'] ) && $branding_opts['remove_restore'] ? true : false;
$hide_server_info = isset( $branding_opts['remove_server_info'] ) && $branding_opts['remove_server_info'] ? true : false;
$hide_connection_detail = isset( $branding_opts['remove_connection_detail'] ) && $branding_opts['remove_connection_detail'] ? true : false;
$sitesToClone = get_option( 'mainwp_child_clone_sites' );
// put here to support hooks to show header.
$is_connected_admin = false;
$connected = ! empty( get_option( 'mainwp_child_pubkey' ) ) ? true : false;
if ( $connected ) {
$current_user = wp_get_current_user();
if ( $current_user ) {
$is_connected_admin = get_option( 'mainwp_child_connected_admin' ) === $current_user->user_login ? true : false;
}
}
$show_clone_funcs = $connected && $is_connected_admin ? true : false;
?>
get_branding_title();
if ( '' === $branding_title ) {
$branding_title = 'MainWP';
} else {
$branding_title = stripslashes( $branding_title );
}
$uniqueId = MainWP_Helper::get_site_unique_id();
$time_limit = get_option( 'mainwp_child_ttl_active_unconnected_site', 20 );
$enable_pwd_auth_connect = get_user_option( 'mainwp_child_user_enable_passwd_auth_connect' );
if ( false === $enable_pwd_auth_connect ) {
$enable_pwd_auth_connect = 1;
update_user_option( get_current_user_id(), 'mainwp_child_user_enable_passwd_auth_connect', 1 );
}
?>