Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/login-customizer/src/Customizer/Initial_Setup.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + /**
3 + * Automatically create a login page for the Customizer to use.
4 + */
5 +
6 + use LoginCustomizer\Essentials;
7 + new Essentials;
8 +
9 + class LoginCustomizerSetup {
10 +
11 + /**
12 + * A reference to an instance of this class.
13 + */
14 + private static $instance;
15 +
16 + /**
17 + * Returns an instance of this class.
18 + */
19 + public static function get_instance() {
20 + if ( null == self::$instance ) {
21 + self::$instance = new LoginCustomizerSetup();
22 + }
23 +
24 + return self::$instance;
25 + }
26 +
27 + /**
28 + * Initializes the plugin by setting filters and administration functions.
29 + */
30 + private function __construct() {
31 + // Add a filter to load check_page function when all plugins have been loaded
32 + add_action( 'wp_loaded', array( $this, 'check_page' ) );
33 + }
34 +
35 + /**
36 + * Check if Login Customizer page exists.
37 + */
38 + public function check_page() {
39 +
40 + $page_id = $this->page_id();
41 + // Update page if exists, else create a new one
42 + if ( $page_id ) {
43 + $this->update_page( $page_id );
44 + } else {
45 + $this->setup_page( 'login-customizer' );
46 + }
47 + }
48 +
49 + /**
50 + * Retrive page ID from DB for login-customizer page.
51 + *
52 + * @since 2.1.6
53 + */
54 + public static function page_id(){
55 +
56 + // Get global wpdb
57 + global $wpdb;
58 +
59 + // Get page ID of page with Login Customizer template
60 + $page_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_name = 'login-customizer' LIMIT 1;" );
61 +
62 + return $page_id;
63 + }
64 +
65 + /**
66 + * If page exists, check if it's setup properly.
67 + */
68 + public function update_page( $page_id ) {
69 +
70 + // Get page template from post meta
71 + $page_template = get_post_meta( $page_id, '_wp_page_template', true );
72 +
73 + // Check if using Login Customizer's page template
74 + if ( $page_template != 'template-login-customizer.php' ) {
75 + update_post_meta( $page_id, '_wp_page_template', 'template-login-customizer.php' );
76 + }
77 +
78 + // Get status of the post
79 + $post_status = get_post_status( $page_id );
80 +
81 + // Check and update post status to publish
82 + if ( $post_status != 'publish' ) {
83 + $page_data = array(
84 + 'ID' => $page_id,
85 + 'post_status' => 'publish',
86 + );
87 + wp_update_post( $page_data );
88 + }
89 +
90 + // Run update_option function
91 + $this->update_option( $page_id );
92 +
93 + }
94 +
95 + /**
96 + * Create new page if Login Customizer page doesn't exist.
97 + */
98 + public function setup_page( $slug ) {
99 +
100 + // Store data for the page
101 + $page_data = array(
102 + 'post_status' => 'publish',
103 + 'post_type' => 'page',
104 + 'post_author' => 1,
105 + 'post_name' => $slug,
106 + 'post_title' => __( 'Login Customizer', 'login-customizer' ),
107 + 'post_content' => __( 'This page is used for Login Customizer plugin. It will not be visible to your readers. Do not delete it.', 'login-customizer' ),
108 + 'comment_status' => 'closed',
109 + );
110 +
111 + // Insert post data
112 + $page_id = wp_insert_post( $page_data );
113 +
114 + // Set page template to Login Customizer template
115 + update_post_meta( $page_id, '_wp_page_template', 'template-login-customizer.php' );
116 +
117 + // Run update_option function
118 + $this->update_option( $page_id );
119 +
120 + }
121 +
122 + /**
123 + * Update plugin options.
124 + */
125 + public function update_option( $page_id ) {
126 +
127 + // Update plugin option with page ID and plugin version
128 + if ( get_option( 'login_customizer_settings' ) !== false ) {
129 + $options = get_option( 'login_customizer_settings', array() );
130 + $options['page'] = $page_id;
131 + $options['version'] = LOGINCUST_FREE_VERSION;
132 + update_option( 'login_customizer_settings', $options );
133 + }
134 +
135 + }
136 +
137 + }
138 +