field-subway-login-page-form.php ➔ subway_login_page_form()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 4
nop 0
dl 0
loc 36
rs 9.0328
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the Subway WordPress Plugin Package.
4
 *
5
 * (c) Joseph Gabito <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @package Subway
11
 */
12
13
if ( ! defined( 'ABSPATH' ) ) {
14
	return;
15
}
16
17
/**
18
 * Callback function for 'subway_login_page' setting
19
 *
20
 * @return void
21
 */
22
function subway_login_page_form() {
23
24
	$subway_login_page_id = intval( get_option( 'subway_login_page' ) );
25
26
	if ( ! empty( $subway_login_page_id ) ) {
27
28
		$login_page_object = get_post( $subway_login_page_id );
29
30
		if ( ! empty( $login_page_object )  && isset( $login_page_object->post_content ) ) {
31
32
			// Automatically prepend the login shortcode if no
33
			// Shortcode exists in the selected login page.
34
			if ( ! has_shortcode( $login_page_object->post_content, 'subway_login' ) ) {
35
36
				$new_post_object = array(
37
				  'ID' => $login_page_object->ID,
38
				  'post_content' => '[subway_login] ' . $login_page_object->post_content,// Prepend Only.
39
				 );
40
41
				wp_update_post( $new_post_object );
42
			}
43
		}
44
	}
45
46
	wp_dropdown_pages(
47
		array(
48
		'name' => 'subway_login_page',
49
		'selected' => intval( $subway_login_page_id ),
50
		'show_option_none' => esc_html__( '---', 'subway' ),
51
		)
52
	);
53
54
	echo '<p class="description">' . sprintf( esc_html__( 'Select a login page and save the changes to make your site private. Selecting "---" (blank) will make your site public. %1$s.', 'subway' ), '<span class="subway-settings-notice">' . esc_html__( 'You need to add "[subway_login]" shortcode in the selected page to show the login form (this will be done automatically after saving)', 'subway' ) ) . '</span></p>';
55
56
	return;
57
}
58