Completed
Pull Request — develop (#1175)
by Naveen
02:31
created
src/admin/class-wordlift-admin-page.php 2 patches
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -18,150 +18,150 @@
 block discarded – undo
18 18
  */
19 19
 abstract class Wordlift_Admin_Page {
20 20
 
21
-	/**
22
-	 * Define the {@link Wordlift_Admin_Page} constructor.
23
-	 *
24
-	 * @since 3.20.0
25
-	 */
26
-	public function __construct() {
27
-
28
-		/**
29
-		 * Filter: wl_feature__enable__screens.
30
-		 *
31
-		 * @param bool whether the screens needed to be registered, defaults to true.
32
-		 *
33
-		 * @return bool
34
-		 * @since 3.27.6
35
-		 */
36
-		if ( apply_filters( 'wl_feature__enable__screens', true ) ) {
37
-			add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 0 );
38
-		}
39
-
40
-	}
41
-
42
-	/**
43
-	 * Get the parent slug.
44
-	 *
45
-	 * @return string The parent slug (default 'wl_admin_menu').
46
-	 * @since 3.11.0
47
-	 *
48
-	 */
49
-	protected function get_parent_slug() {
50
-
51
-		return 'wl_admin_menu';
52
-	}
53
-
54
-	/**
55
-	 * Get the required capability.
56
-	 *
57
-	 * @return string The capability (default 'manage_options').
58
-	 * @since 3.11.0
59
-	 *
60
-	 */
61
-	protected function get_capability() {
62
-
63
-		return 'manage_options';
64
-	}
65
-
66
-	/**
67
-	 * Get the page title. Will be translated.
68
-	 *
69
-	 * @return string The page title.
70
-	 * @since 3.11.0
71
-	 *
72
-	 */
73
-	abstract function get_page_title();
74
-
75
-	/**
76
-	 * Get the menu title. Will be translated.
77
-	 *
78
-	 * @return string The menu title.
79
-	 * @since 3.11.0
80
-	 *
81
-	 */
82
-	abstract function get_menu_title();
83
-
84
-	/**
85
-	 * Get the menu slug.
86
-	 *
87
-	 * @return string The menu slug.
88
-	 * @since 3.11.0
89
-	 *
90
-	 */
91
-	abstract function get_menu_slug();
92
-
93
-	/**
94
-	 * Get the page url.
95
-	 *
96
-	 * @return string The escaped url of the admin page
97
-	 * @since 3.14.0
98
-	 *
99
-	 */
100
-	function get_url() {
101
-
102
-		// ideally should have used menu_page_url, but it is loaded later than some usages.
103
-		$url = admin_url( 'admin.php?page=' . $this->get_menu_slug() );
104
-
105
-		return esc_url( $url );
106
-	}
107
-
108
-	/**
109
-	 * Get the partial file name, used in the {@link render} function.
110
-	 *
111
-	 * @return string The partial file name.
112
-	 * @since 3.11.0
113
-	 *
114
-	 */
115
-	abstract function get_partial_name();
116
-
117
-	/**
118
-	 * The `admin_menu` callback. Will call {@link add_submenu_page} to add the
119
-	 * page to the admin menu.
120
-	 *
121
-	 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
122
-	 * @since 3.11.0
123
-	 *
124
-	 */
125
-	public function admin_menu() {
126
-		// Add the sub-menu page.
127
-		//
128
-		// See http://codex.wordpress.org/Function_Reference/add_submenu_page
129
-		$page = add_submenu_page(
130
-			$this->get_parent_slug(),
131
-			$this->get_page_title(),
132
-			$this->get_menu_title(),
133
-			$this->get_capability(),                   // The required capability, provided by the calling hook.
134
-			$this->get_menu_slug(),
135
-			array( $this, 'render' )
136
-		);
137
-
138
-		// Set a hook to enqueue scripts only when the settings page is displayed.
139
-		add_action( 'admin_print_scripts-' . $page, array(
140
-			$this,
141
-			'enqueue_scripts',
142
-		) );
143
-
144
-		// Finally return the page hook_suffix.
145
-		return $page;
146
-	}
147
-
148
-	/**
149
-	 * Enqueue scripts for the specific page. Subclasses can override this function
150
-	 * to provide their own styles/scripts.
151
-	 *
152
-	 * @since 3.11.0
153
-	 */
154
-	public function enqueue_scripts() {
155
-	}
156
-
157
-	/**
158
-	 * Render the page.
159
-	 */
160
-	public function render() {
161
-
162
-		// Include the partial.
163
-		include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name() );
164
-
165
-	}
21
+    /**
22
+     * Define the {@link Wordlift_Admin_Page} constructor.
23
+     *
24
+     * @since 3.20.0
25
+     */
26
+    public function __construct() {
27
+
28
+        /**
29
+         * Filter: wl_feature__enable__screens.
30
+         *
31
+         * @param bool whether the screens needed to be registered, defaults to true.
32
+         *
33
+         * @return bool
34
+         * @since 3.27.6
35
+         */
36
+        if ( apply_filters( 'wl_feature__enable__screens', true ) ) {
37
+            add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 0 );
38
+        }
39
+
40
+    }
41
+
42
+    /**
43
+     * Get the parent slug.
44
+     *
45
+     * @return string The parent slug (default 'wl_admin_menu').
46
+     * @since 3.11.0
47
+     *
48
+     */
49
+    protected function get_parent_slug() {
50
+
51
+        return 'wl_admin_menu';
52
+    }
53
+
54
+    /**
55
+     * Get the required capability.
56
+     *
57
+     * @return string The capability (default 'manage_options').
58
+     * @since 3.11.0
59
+     *
60
+     */
61
+    protected function get_capability() {
62
+
63
+        return 'manage_options';
64
+    }
65
+
66
+    /**
67
+     * Get the page title. Will be translated.
68
+     *
69
+     * @return string The page title.
70
+     * @since 3.11.0
71
+     *
72
+     */
73
+    abstract function get_page_title();
74
+
75
+    /**
76
+     * Get the menu title. Will be translated.
77
+     *
78
+     * @return string The menu title.
79
+     * @since 3.11.0
80
+     *
81
+     */
82
+    abstract function get_menu_title();
83
+
84
+    /**
85
+     * Get the menu slug.
86
+     *
87
+     * @return string The menu slug.
88
+     * @since 3.11.0
89
+     *
90
+     */
91
+    abstract function get_menu_slug();
92
+
93
+    /**
94
+     * Get the page url.
95
+     *
96
+     * @return string The escaped url of the admin page
97
+     * @since 3.14.0
98
+     *
99
+     */
100
+    function get_url() {
101
+
102
+        // ideally should have used menu_page_url, but it is loaded later than some usages.
103
+        $url = admin_url( 'admin.php?page=' . $this->get_menu_slug() );
104
+
105
+        return esc_url( $url );
106
+    }
107
+
108
+    /**
109
+     * Get the partial file name, used in the {@link render} function.
110
+     *
111
+     * @return string The partial file name.
112
+     * @since 3.11.0
113
+     *
114
+     */
115
+    abstract function get_partial_name();
116
+
117
+    /**
118
+     * The `admin_menu` callback. Will call {@link add_submenu_page} to add the
119
+     * page to the admin menu.
120
+     *
121
+     * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
122
+     * @since 3.11.0
123
+     *
124
+     */
125
+    public function admin_menu() {
126
+        // Add the sub-menu page.
127
+        //
128
+        // See http://codex.wordpress.org/Function_Reference/add_submenu_page
129
+        $page = add_submenu_page(
130
+            $this->get_parent_slug(),
131
+            $this->get_page_title(),
132
+            $this->get_menu_title(),
133
+            $this->get_capability(),                   // The required capability, provided by the calling hook.
134
+            $this->get_menu_slug(),
135
+            array( $this, 'render' )
136
+        );
137
+
138
+        // Set a hook to enqueue scripts only when the settings page is displayed.
139
+        add_action( 'admin_print_scripts-' . $page, array(
140
+            $this,
141
+            'enqueue_scripts',
142
+        ) );
143
+
144
+        // Finally return the page hook_suffix.
145
+        return $page;
146
+    }
147
+
148
+    /**
149
+     * Enqueue scripts for the specific page. Subclasses can override this function
150
+     * to provide their own styles/scripts.
151
+     *
152
+     * @since 3.11.0
153
+     */
154
+    public function enqueue_scripts() {
155
+    }
156
+
157
+    /**
158
+     * Render the page.
159
+     */
160
+    public function render() {
161
+
162
+        // Include the partial.
163
+        include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name() );
164
+
165
+    }
166 166
 
167 167
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
 		 * @return bool
34 34
 		 * @since 3.27.6
35 35
 		 */
36
-		if ( apply_filters( 'wl_feature__enable__screens', true ) ) {
37
-			add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 0 );
36
+		if (apply_filters('wl_feature__enable__screens', true)) {
37
+			add_action('admin_menu', array($this, 'admin_menu'), 10, 0);
38 38
 		}
39 39
 
40 40
 	}
@@ -100,9 +100,9 @@  discard block
 block discarded – undo
100 100
 	function get_url() {
101 101
 
102 102
 		// ideally should have used menu_page_url, but it is loaded later than some usages.
103
-		$url = admin_url( 'admin.php?page=' . $this->get_menu_slug() );
103
+		$url = admin_url('admin.php?page='.$this->get_menu_slug());
104 104
 
105
-		return esc_url( $url );
105
+		return esc_url($url);
106 106
 	}
107 107
 
108 108
 	/**
@@ -130,16 +130,16 @@  discard block
 block discarded – undo
130 130
 			$this->get_parent_slug(),
131 131
 			$this->get_page_title(),
132 132
 			$this->get_menu_title(),
133
-			$this->get_capability(),                   // The required capability, provided by the calling hook.
133
+			$this->get_capability(), // The required capability, provided by the calling hook.
134 134
 			$this->get_menu_slug(),
135
-			array( $this, 'render' )
135
+			array($this, 'render')
136 136
 		);
137 137
 
138 138
 		// Set a hook to enqueue scripts only when the settings page is displayed.
139
-		add_action( 'admin_print_scripts-' . $page, array(
139
+		add_action('admin_print_scripts-'.$page, array(
140 140
 			$this,
141 141
 			'enqueue_scripts',
142
-		) );
142
+		));
143 143
 
144 144
 		// Finally return the page hook_suffix.
145 145
 		return $page;
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	public function render() {
161 161
 
162 162
 		// Include the partial.
163
-		include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name() );
163
+		include(plugin_dir_path(__FILE__).'partials/'.$this->get_partial_name());
164 164
 
165 165
 	}
166 166
 
Please login to merge, or discard this patch.
src/widgets/wordlift_widget_geo.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -7,57 +7,57 @@  discard block
 block discarded – undo
7 7
  * Class WordLift_Geo_Widget
8 8
  */
9 9
 class WordLift_Geo_Widget extends WP_Widget {
10
-	/**
11
-	 * Sets up the widgets name etc
12
-	 */
13
-	public function __construct() {
14
-		// Initialize the Widget.
15
-		parent::__construct(
16
-			'wl_geo_widget', // Base ID
17
-			__( 'Geo Widget', 'wordlift' ), // Name
18
-			array( 'description' => __( 'Geo Widget description', 'wordlift' ), ) // Args
19
-		);
20
-	}
10
+    /**
11
+     * Sets up the widgets name etc
12
+     */
13
+    public function __construct() {
14
+        // Initialize the Widget.
15
+        parent::__construct(
16
+            'wl_geo_widget', // Base ID
17
+            __( 'Geo Widget', 'wordlift' ), // Name
18
+            array( 'description' => __( 'Geo Widget description', 'wordlift' ), ) // Args
19
+        );
20
+    }
21 21
 
22
-	/**
23
-	 * Outputs the content of the widget
24
-	 *
25
-	 * @param array $args
26
-	 * @param array $instance
27
-	 */
28
-	public function widget( $args, $instance ) {
29
-		// Get the widget's title.
30
-		$title = apply_filters( 'widget_title', $instance['title'] );
22
+    /**
23
+     * Outputs the content of the widget
24
+     *
25
+     * @param array $args
26
+     * @param array $instance
27
+     */
28
+    public function widget( $args, $instance ) {
29
+        // Get the widget's title.
30
+        $title = apply_filters( 'widget_title', $instance['title'] );
31 31
 
32
-		// Print the HTML output.
33
-		echo $args['before_widget'];
34
-		if ( ! empty( $title ) ) {
35
-			echo $args['before_title'] . $title . $args['after_title'];
36
-		}
32
+        // Print the HTML output.
33
+        echo $args['before_widget'];
34
+        if ( ! empty( $title ) ) {
35
+            echo $args['before_title'] . $title . $args['after_title'];
36
+        }
37 37
 
38
-		// Print the geomap shortcode
39
-		// ( global = true - because it is not post-specific)
40
-		echo do_shortcode( '[wl_geomap global=true]' );
38
+        // Print the geomap shortcode
39
+        // ( global = true - because it is not post-specific)
40
+        echo do_shortcode( '[wl_geomap global=true]' );
41 41
 
42
-		echo $args['after_widget'];
43
-	}
42
+        echo $args['after_widget'];
43
+    }
44 44
 
45
-	/**
46
-	 * Ouputs the options form on admin
47
-	 *
48
-	 * @param array $instance The widget options
49
-	 */
50
-	public
51
-	function form(
52
-		$instance
53
-	) {
45
+    /**
46
+     * Ouputs the options form on admin
47
+     *
48
+     * @param array $instance The widget options
49
+     */
50
+    public
51
+    function form(
52
+        $instance
53
+    ) {
54 54
 
55
-		if ( isset( $instance['title'] ) ) {
56
-			$title = $instance['title'];
57
-		} else {
58
-			$title = __( 'New title', 'wordlift' );
59
-		}
60
-		?>
55
+        if ( isset( $instance['title'] ) ) {
56
+            $title = $instance['title'];
57
+        } else {
58
+            $title = __( 'New title', 'wordlift' );
59
+        }
60
+        ?>
61 61
         <p>
62 62
             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:' ); ?></label>
63 63
             <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>"
@@ -66,26 +66,26 @@  discard block
 block discarded – undo
66 66
         </p>
67 67
 		<?php
68 68
 
69
-	}
69
+    }
70 70
 
71
-	/**
72
-	 * Processing widget options on save
73
-	 *
74
-	 * @param array $new_instance The new options
75
-	 * @param array $old_instance The previous options
76
-	 */
77
-	public
78
-	function update(
79
-		$new_instance, $old_instance
80
-	) {
71
+    /**
72
+     * Processing widget options on save
73
+     *
74
+     * @param array $new_instance The new options
75
+     * @param array $old_instance The previous options
76
+     */
77
+    public
78
+    function update(
79
+        $new_instance, $old_instance
80
+    ) {
81 81
 
82
-		$instance          = array();
83
-		$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
82
+        $instance          = array();
83
+        $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
84 84
 
85
-		return $instance;
86
-	}
85
+        return $instance;
86
+    }
87 87
 }
88 88
 
89 89
 function wl_register_geo_widget() {
90
-	register_widget( 'WordLift_Geo_Widget' );
90
+    register_widget( 'WordLift_Geo_Widget' );
91 91
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -14,8 +14,8 @@  discard block
 block discarded – undo
14 14
 		// Initialize the Widget.
15 15
 		parent::__construct(
16 16
 			'wl_geo_widget', // Base ID
17
-			__( 'Geo Widget', 'wordlift' ), // Name
18
-			array( 'description' => __( 'Geo Widget description', 'wordlift' ), ) // Args
17
+			__('Geo Widget', 'wordlift'), // Name
18
+			array('description' => __('Geo Widget description', 'wordlift'),) // Args
19 19
 		);
20 20
 	}
21 21
 
@@ -25,19 +25,19 @@  discard block
 block discarded – undo
25 25
 	 * @param array $args
26 26
 	 * @param array $instance
27 27
 	 */
28
-	public function widget( $args, $instance ) {
28
+	public function widget($args, $instance) {
29 29
 		// Get the widget's title.
30
-		$title = apply_filters( 'widget_title', $instance['title'] );
30
+		$title = apply_filters('widget_title', $instance['title']);
31 31
 
32 32
 		// Print the HTML output.
33 33
 		echo $args['before_widget'];
34
-		if ( ! empty( $title ) ) {
35
-			echo $args['before_title'] . $title . $args['after_title'];
34
+		if ( ! empty($title)) {
35
+			echo $args['before_title'].$title.$args['after_title'];
36 36
 		}
37 37
 
38 38
 		// Print the geomap shortcode
39 39
 		// ( global = true - because it is not post-specific)
40
-		echo do_shortcode( '[wl_geomap global=true]' );
40
+		echo do_shortcode('[wl_geomap global=true]');
41 41
 
42 42
 		echo $args['after_widget'];
43 43
 	}
@@ -52,17 +52,17 @@  discard block
 block discarded – undo
52 52
 		$instance
53 53
 	) {
54 54
 
55
-		if ( isset( $instance['title'] ) ) {
55
+		if (isset($instance['title'])) {
56 56
 			$title = $instance['title'];
57 57
 		} else {
58
-			$title = __( 'New title', 'wordlift' );
58
+			$title = __('New title', 'wordlift');
59 59
 		}
60 60
 		?>
61 61
         <p>
62
-            <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:' ); ?></label>
63
-            <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>"
64
-                   name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"
65
-                   value="<?php echo esc_attr( $title ); ?>">
62
+            <label for="<?php echo $this->get_field_id('title'); ?>"><?php esc_html_e('Title:'); ?></label>
63
+            <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
64
+                   name="<?php echo $this->get_field_name('title'); ?>" type="text"
65
+                   value="<?php echo esc_attr($title); ?>">
66 66
         </p>
67 67
 		<?php
68 68
 
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
80 80
 	) {
81 81
 
82 82
 		$instance          = array();
83
-		$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
83
+		$instance['title'] = ( ! empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
84 84
 
85 85
 		return $instance;
86 86
 	}
87 87
 }
88 88
 
89 89
 function wl_register_geo_widget() {
90
-	register_widget( 'WordLift_Geo_Widget' );
90
+	register_widget('WordLift_Geo_Widget');
91 91
 }
Please login to merge, or discard this patch.
src/widgets/wordlift_widget_timeline.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -2,50 +2,50 @@
 block discarded – undo
2 2
 
3 3
 class Wordlift_Timeline_Widget extends WP_Widget {
4 4
 
5
-	/**
6
-	 * Sets up the widgets name etc
7
-	 */
8
-	public function __construct() {
9
-		// widget actual processes
10
-		parent::__construct(
11
-			'wl_timeline_widget', // Base ID
12
-			__( 'WordLift Timeline Widget', 'wordlift' ), // Name
13
-			array( 'description' => __( 'Displays entities of type event using an interactive timeline.', 'wordlift' ), ) // Args
14
-		);
15
-	}
5
+    /**
6
+     * Sets up the widgets name etc
7
+     */
8
+    public function __construct() {
9
+        // widget actual processes
10
+        parent::__construct(
11
+            'wl_timeline_widget', // Base ID
12
+            __( 'WordLift Timeline Widget', 'wordlift' ), // Name
13
+            array( 'description' => __( 'Displays entities of type event using an interactive timeline.', 'wordlift' ), ) // Args
14
+        );
15
+    }
16 16
 
17
-	/**
18
-	 * Outputs the content of the widget
19
-	 *
20
-	 * @param array $args
21
-	 * @param array $instance
22
-	 */
23
-	public function widget( $args, $instance ) {
24
-		// outputs the content of the widget	
25
-		echo do_shortcode( '[wl_timeline global=true]' );
26
-	}
17
+    /**
18
+     * Outputs the content of the widget
19
+     *
20
+     * @param array $args
21
+     * @param array $instance
22
+     */
23
+    public function widget( $args, $instance ) {
24
+        // outputs the content of the widget	
25
+        echo do_shortcode( '[wl_timeline global=true]' );
26
+    }
27 27
 
28
-	/**
29
-	 * Outputs the options form on admin
30
-	 *
31
-	 * @param array $instance The widget options
32
-	 */
33
-	public function form( $instance ) {
34
-		// outputs the options form on admin
35
-	}
28
+    /**
29
+     * Outputs the options form on admin
30
+     *
31
+     * @param array $instance The widget options
32
+     */
33
+    public function form( $instance ) {
34
+        // outputs the options form on admin
35
+    }
36 36
 
37
-	/**
38
-	 * Processing widget options on save
39
-	 *
40
-	 * @param array $new_instance The new options
41
-	 * @param array $old_instance The previous options
42
-	 */
43
-	public function update( $new_instance, $old_instance ) {
44
-		// processes widget options to be saved
45
-	}
37
+    /**
38
+     * Processing widget options on save
39
+     *
40
+     * @param array $new_instance The new options
41
+     * @param array $old_instance The previous options
42
+     */
43
+    public function update( $new_instance, $old_instance ) {
44
+        // processes widget options to be saved
45
+    }
46 46
 }
47 47
 
48 48
 function wl_register_timeline_widget() {
49 49
 
50
-	register_widget( 'WordLift_Timeline_Widget' );
50
+    register_widget( 'WordLift_Timeline_Widget' );
51 51
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,8 +9,8 @@  discard block
 block discarded – undo
9 9
 		// widget actual processes
10 10
 		parent::__construct(
11 11
 			'wl_timeline_widget', // Base ID
12
-			__( 'WordLift Timeline Widget', 'wordlift' ), // Name
13
-			array( 'description' => __( 'Displays entities of type event using an interactive timeline.', 'wordlift' ), ) // Args
12
+			__('WordLift Timeline Widget', 'wordlift'), // Name
13
+			array('description' => __('Displays entities of type event using an interactive timeline.', 'wordlift'),) // Args
14 14
 		);
15 15
 	}
16 16
 
@@ -20,9 +20,9 @@  discard block
 block discarded – undo
20 20
 	 * @param array $args
21 21
 	 * @param array $instance
22 22
 	 */
23
-	public function widget( $args, $instance ) {
23
+	public function widget($args, $instance) {
24 24
 		// outputs the content of the widget	
25
-		echo do_shortcode( '[wl_timeline global=true]' );
25
+		echo do_shortcode('[wl_timeline global=true]');
26 26
 	}
27 27
 
28 28
 	/**
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	 *
31 31
 	 * @param array $instance The widget options
32 32
 	 */
33
-	public function form( $instance ) {
33
+	public function form($instance) {
34 34
 		// outputs the options form on admin
35 35
 	}
36 36
 
@@ -40,12 +40,12 @@  discard block
 block discarded – undo
40 40
 	 * @param array $new_instance The new options
41 41
 	 * @param array $old_instance The previous options
42 42
 	 */
43
-	public function update( $new_instance, $old_instance ) {
43
+	public function update($new_instance, $old_instance) {
44 44
 		// processes widget options to be saved
45 45
 	}
46 46
 }
47 47
 
48 48
 function wl_register_timeline_widget() {
49 49
 
50
-	register_widget( 'WordLift_Timeline_Widget' );
50
+	register_widget('WordLift_Timeline_Widget');
51 51
 }
Please login to merge, or discard this patch.
src/widgets/class-wordlift-chord-widget.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -10,54 +10,54 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class Wordlift_Chord_Widget extends WP_Widget {
12 12
 
13
-	/**
14
-	 * Sets up the widgets name etc
15
-	 */
16
-	public function __construct() {
17
-		// widget actual processes.
18
-		parent::__construct(
19
-			'wl_chord_widget', // Base ID.
20
-			__( 'Chord Widget', 'wordlift' ), // Name.
21
-			array(
22
-				'description' => __( 'The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift' ),
23
-			) // Args.
24
-		);
25
-	}
13
+    /**
14
+     * Sets up the widgets name etc
15
+     */
16
+    public function __construct() {
17
+        // widget actual processes.
18
+        parent::__construct(
19
+            'wl_chord_widget', // Base ID.
20
+            __( 'Chord Widget', 'wordlift' ), // Name.
21
+            array(
22
+                'description' => __( 'The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift' ),
23
+            ) // Args.
24
+        );
25
+    }
26 26
 
27
-	/**
28
-	 * Outputs the content of the widget
29
-	 *
30
-	 * @param array $args widget args.
31
-	 * @param array $instance widget instance.
32
-	 */
33
-	// @codingStandardsIgnoreLine Generic.CodeAnalysis.UnusedFunctionParameter.Found
34
-	public function widget( $args, $instance ) {
35
-		// outputs the content of the widget.
36
-		echo do_shortcode( '[wl_chord global=true]' );
37
-	}
27
+    /**
28
+     * Outputs the content of the widget
29
+     *
30
+     * @param array $args widget args.
31
+     * @param array $instance widget instance.
32
+     */
33
+    // @codingStandardsIgnoreLine Generic.CodeAnalysis.UnusedFunctionParameter.Found
34
+    public function widget( $args, $instance ) {
35
+        // outputs the content of the widget.
36
+        echo do_shortcode( '[wl_chord global=true]' );
37
+    }
38 38
 
39
-	/**
40
-	 * Outputs the options form on admin
41
-	 *
42
-	 * @param array $instance The widget options.
43
-	 *
44
-	 * @return string|void
45
-	 */
46
-	public function form( $instance ) {
47
-		// outputs the options form on admin.
48
-	}
39
+    /**
40
+     * Outputs the options form on admin
41
+     *
42
+     * @param array $instance The widget options.
43
+     *
44
+     * @return string|void
45
+     */
46
+    public function form( $instance ) {
47
+        // outputs the options form on admin.
48
+    }
49 49
 
50
-	/**
51
-	 * Processing widget options on save
52
-	 *
53
-	 * @param array $new_instance The new options.
54
-	 * @param array $old_instance The previous options.
55
-	 *
56
-	 * @return array|void
57
-	 */
58
-	public function update( $new_instance, $old_instance ) {
59
-		// processes widget options to be saved.
60
-	}
50
+    /**
51
+     * Processing widget options on save
52
+     *
53
+     * @param array $new_instance The new options.
54
+     * @param array $old_instance The previous options.
55
+     *
56
+     * @return array|void
57
+     */
58
+    public function update( $new_instance, $old_instance ) {
59
+        // processes widget options to be saved.
60
+    }
61 61
 }
62 62
 
63 63
 /**
@@ -67,5 +67,5 @@  discard block
 block discarded – undo
67 67
  */
68 68
 function wl_register_chord_widget() {
69 69
 
70
-	register_widget( 'WordLift_Chord_Widget' );
70
+    register_widget( 'WordLift_Chord_Widget' );
71 71
 }
72 72
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -17,9 +17,9 @@  discard block
 block discarded – undo
17 17
 		// widget actual processes.
18 18
 		parent::__construct(
19 19
 			'wl_chord_widget', // Base ID.
20
-			__( 'Chord Widget', 'wordlift' ), // Name.
20
+			__('Chord Widget', 'wordlift'), // Name.
21 21
 			array(
22
-				'description' => __( 'The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift' ),
22
+				'description' => __('The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift'),
23 23
 			) // Args.
24 24
 		);
25 25
 	}
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
 	 * @param array $instance widget instance.
32 32
 	 */
33 33
 	// @codingStandardsIgnoreLine Generic.CodeAnalysis.UnusedFunctionParameter.Found
34
-	public function widget( $args, $instance ) {
34
+	public function widget($args, $instance) {
35 35
 		// outputs the content of the widget.
36
-		echo do_shortcode( '[wl_chord global=true]' );
36
+		echo do_shortcode('[wl_chord global=true]');
37 37
 	}
38 38
 
39 39
 	/**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 *
44 44
 	 * @return string|void
45 45
 	 */
46
-	public function form( $instance ) {
46
+	public function form($instance) {
47 47
 		// outputs the options form on admin.
48 48
 	}
49 49
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 *
56 56
 	 * @return array|void
57 57
 	 */
58
-	public function update( $new_instance, $old_instance ) {
58
+	public function update($new_instance, $old_instance) {
59 59
 		// processes widget options to be saved.
60 60
 	}
61 61
 }
@@ -67,5 +67,5 @@  discard block
 block discarded – undo
67 67
  */
68 68
 function wl_register_chord_widget() {
69 69
 
70
-	register_widget( 'WordLift_Chord_Widget' );
70
+	register_widget('WordLift_Chord_Widget');
71 71
 }
72 72
\ No newline at end of file
Please login to merge, or discard this patch.
wordlift/external-plugin-hooks/recipe-maker/class-recipe-maker-warning.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -15,6 +15,9 @@
 block discarded – undo
15 15
 	 */
16 16
 	private $recipe_maker_validation_service;
17 17
 
18
+	/**
19
+	 * @param Recipe_Maker_Validation_Service $recipe_maker_validation_service
20
+	 */
18 21
 	public function __construct( $recipe_maker_validation_service ) {
19 22
 		$this->recipe_maker_validation_service = $recipe_maker_validation_service;
20 23
 		/**
Please login to merge, or discard this patch.
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -10,99 +10,99 @@
 block discarded – undo
10 10
  */
11 11
 class Recipe_Maker_Warning {
12 12
 
13
-	/**
14
-	 * @var Recipe_Maker_Validation_Service
15
-	 */
16
-	private $recipe_maker_validation_service;
17
-
18
-	public function __construct( $recipe_maker_validation_service ) {
19
-		$this->recipe_maker_validation_service = $recipe_maker_validation_service;
20
-		/**
21
-		 * Filter: wl_feature__enable__notices.
22
-		 *
23
-		 * @param bool whether the notices needs to be enabled or not.
24
-		 *
25
-		 * @return bool
26
-		 * @since 3.27.6
27
-		 */
28
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
29
-			add_action( 'admin_notices', array( $this, 'display_image_size_warning' ) );
30
-		}
31
-	}
32
-
33
-	/**
34
-	 * Show the warning after applying the conditions.
35
-	 */
36
-	public function display_image_size_warning() {
37
-
38
-		// Check if we are on the post.
39
-		if ( ! get_post() instanceof \WP_Post ) {
40
-			return false;
41
-		}
42
-		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
43
-			return false;
44
-		}
45
-		$post_id = get_the_ID();
46
-
47
-		// Dont show notification if there is no recipes referred by the post.
48
-		if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) {
49
-			return false;
50
-		}
51
-
52
-		$recipe_with_image_warnings = $this->get_warnings( $post_id );
53
-
54
-		if ( count( $recipe_with_image_warnings ) > 0 ) {
55
-			// Show notification.
56
-			?>
13
+    /**
14
+     * @var Recipe_Maker_Validation_Service
15
+     */
16
+    private $recipe_maker_validation_service;
17
+
18
+    public function __construct( $recipe_maker_validation_service ) {
19
+        $this->recipe_maker_validation_service = $recipe_maker_validation_service;
20
+        /**
21
+         * Filter: wl_feature__enable__notices.
22
+         *
23
+         * @param bool whether the notices needs to be enabled or not.
24
+         *
25
+         * @return bool
26
+         * @since 3.27.6
27
+         */
28
+        if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
29
+            add_action( 'admin_notices', array( $this, 'display_image_size_warning' ) );
30
+        }
31
+    }
32
+
33
+    /**
34
+     * Show the warning after applying the conditions.
35
+     */
36
+    public function display_image_size_warning() {
37
+
38
+        // Check if we are on the post.
39
+        if ( ! get_post() instanceof \WP_Post ) {
40
+            return false;
41
+        }
42
+        if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
43
+            return false;
44
+        }
45
+        $post_id = get_the_ID();
46
+
47
+        // Dont show notification if there is no recipes referred by the post.
48
+        if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) {
49
+            return false;
50
+        }
51
+
52
+        $recipe_with_image_warnings = $this->get_warnings( $post_id );
53
+
54
+        if ( count( $recipe_with_image_warnings ) > 0 ) {
55
+            // Show notification.
56
+            ?>
57 57
             <div class="notice notice-warning is-dismissible">
58 58
                 <p><?php echo __( 'The following recipes didnt have minimum image size of 1200 x 1200 px', 'wordlift' ); ?></p>
59 59
                 <ol>
60 60
 					<?php
61
-					foreach ( $recipe_with_image_warnings as $post_id ) {
62
-						echo "<li>" . get_the_title( $post_id ) . "</li>";
63
-					}
64
-					?>
61
+                    foreach ( $recipe_with_image_warnings as $post_id ) {
62
+                        echo "<li>" . get_the_title( $post_id ) . "</li>";
63
+                    }
64
+                    ?>
65 65
                 </ol>
66 66
             </div>
67 67
 			<?php
68
-		}
69
-
70
-	}
71
-
72
-	/**
73
-	 * @param $post_id
74
-	 *
75
-	 * @return array
76
-	 */
77
-	private function get_warnings( $post_id ) {
78
-
79
-		$recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
80
-
81
-		// Dont show duplicate warnings.
82
-		$recipe_ids = array_unique( $recipe_ids );
83
-
84
-		$recipe_with_image_warnings = array();
85
-
86
-		foreach ( $recipe_ids as $recipe_id ) {
87
-			$recipe     = \WPRM_Recipe_Manager::get_recipe( $recipe_id );
88
-			$image_id   = $recipe->image_id();
89
-			$image_data = wp_get_attachment_image_src( $image_id, array( 1200, 1200 ) );
90
-			if ( ! is_array( $image_data ) ) {
91
-				continue;
92
-			}
93
-			$image_width  = array_key_exists( 1, $image_data ) ? $image_data [1] : false;
94
-			$image_height = array_key_exists( 2, $image_data ) ? $image_data [2] : false;
95
-			if ( ! ( $image_height && $image_width ) ) {
96
-				continue;
97
-			}
98
-
99
-			if ( $image_height < 1200 || $image_width < 1200 ) {
100
-				// Image size not present in 1200 * 1200, show a warning.
101
-				$recipe_with_image_warnings[] = $recipe_id;
102
-			}
103
-		}
104
-
105
-		return $recipe_with_image_warnings;
106
-	}
68
+        }
69
+
70
+    }
71
+
72
+    /**
73
+     * @param $post_id
74
+     *
75
+     * @return array
76
+     */
77
+    private function get_warnings( $post_id ) {
78
+
79
+        $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
80
+
81
+        // Dont show duplicate warnings.
82
+        $recipe_ids = array_unique( $recipe_ids );
83
+
84
+        $recipe_with_image_warnings = array();
85
+
86
+        foreach ( $recipe_ids as $recipe_id ) {
87
+            $recipe     = \WPRM_Recipe_Manager::get_recipe( $recipe_id );
88
+            $image_id   = $recipe->image_id();
89
+            $image_data = wp_get_attachment_image_src( $image_id, array( 1200, 1200 ) );
90
+            if ( ! is_array( $image_data ) ) {
91
+                continue;
92
+            }
93
+            $image_width  = array_key_exists( 1, $image_data ) ? $image_data [1] : false;
94
+            $image_height = array_key_exists( 2, $image_data ) ? $image_data [2] : false;
95
+            if ( ! ( $image_height && $image_width ) ) {
96
+                continue;
97
+            }
98
+
99
+            if ( $image_height < 1200 || $image_width < 1200 ) {
100
+                // Image size not present in 1200 * 1200, show a warning.
101
+                $recipe_with_image_warnings[] = $recipe_id;
102
+            }
103
+        }
104
+
105
+        return $recipe_with_image_warnings;
106
+    }
107 107
 
108 108
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	 */
16 16
 	private $recipe_maker_validation_service;
17 17
 
18
-	public function __construct( $recipe_maker_validation_service ) {
18
+	public function __construct($recipe_maker_validation_service) {
19 19
 		$this->recipe_maker_validation_service = $recipe_maker_validation_service;
20 20
 		/**
21 21
 		 * Filter: wl_feature__enable__notices.
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
 		 * @return bool
26 26
 		 * @since 3.27.6
27 27
 		 */
28
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
29
-			add_action( 'admin_notices', array( $this, 'display_image_size_warning' ) );
28
+		if (apply_filters('wl_feature__enable__notices', true)) {
29
+			add_action('admin_notices', array($this, 'display_image_size_warning'));
30 30
 		}
31 31
 	}
32 32
 
@@ -36,30 +36,30 @@  discard block
 block discarded – undo
36 36
 	public function display_image_size_warning() {
37 37
 
38 38
 		// Check if we are on the post.
39
-		if ( ! get_post() instanceof \WP_Post ) {
39
+		if ( ! get_post() instanceof \WP_Post) {
40 40
 			return false;
41 41
 		}
42
-		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available() ) {
42
+		if ( ! $this->recipe_maker_validation_service->is_wp_recipe_maker_available()) {
43 43
 			return false;
44 44
 		}
45 45
 		$post_id = get_the_ID();
46 46
 
47 47
 		// Dont show notification if there is no recipes referred by the post.
48
-		if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post( $post_id ) ) {
48
+		if ( ! $this->recipe_maker_validation_service->is_atleast_once_recipe_present_in_the_post($post_id)) {
49 49
 			return false;
50 50
 		}
51 51
 
52
-		$recipe_with_image_warnings = $this->get_warnings( $post_id );
52
+		$recipe_with_image_warnings = $this->get_warnings($post_id);
53 53
 
54
-		if ( count( $recipe_with_image_warnings ) > 0 ) {
54
+		if (count($recipe_with_image_warnings) > 0) {
55 55
 			// Show notification.
56 56
 			?>
57 57
             <div class="notice notice-warning is-dismissible">
58
-                <p><?php echo __( 'The following recipes didnt have minimum image size of 1200 x 1200 px', 'wordlift' ); ?></p>
58
+                <p><?php echo __('The following recipes didnt have minimum image size of 1200 x 1200 px', 'wordlift'); ?></p>
59 59
                 <ol>
60 60
 					<?php
61
-					foreach ( $recipe_with_image_warnings as $post_id ) {
62
-						echo "<li>" . get_the_title( $post_id ) . "</li>";
61
+					foreach ($recipe_with_image_warnings as $post_id) {
62
+						echo "<li>".get_the_title($post_id)."</li>";
63 63
 					}
64 64
 					?>
65 65
                 </ol>
@@ -74,29 +74,29 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @return array
76 76
 	 */
77
-	private function get_warnings( $post_id ) {
77
+	private function get_warnings($post_id) {
78 78
 
79
-		$recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
79
+		$recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post($post_id);
80 80
 
81 81
 		// Dont show duplicate warnings.
82
-		$recipe_ids = array_unique( $recipe_ids );
82
+		$recipe_ids = array_unique($recipe_ids);
83 83
 
84 84
 		$recipe_with_image_warnings = array();
85 85
 
86
-		foreach ( $recipe_ids as $recipe_id ) {
87
-			$recipe     = \WPRM_Recipe_Manager::get_recipe( $recipe_id );
86
+		foreach ($recipe_ids as $recipe_id) {
87
+			$recipe     = \WPRM_Recipe_Manager::get_recipe($recipe_id);
88 88
 			$image_id   = $recipe->image_id();
89
-			$image_data = wp_get_attachment_image_src( $image_id, array( 1200, 1200 ) );
90
-			if ( ! is_array( $image_data ) ) {
89
+			$image_data = wp_get_attachment_image_src($image_id, array(1200, 1200));
90
+			if ( ! is_array($image_data)) {
91 91
 				continue;
92 92
 			}
93
-			$image_width  = array_key_exists( 1, $image_data ) ? $image_data [1] : false;
94
-			$image_height = array_key_exists( 2, $image_data ) ? $image_data [2] : false;
95
-			if ( ! ( $image_height && $image_width ) ) {
93
+			$image_width  = array_key_exists(1, $image_data) ? $image_data [1] : false;
94
+			$image_height = array_key_exists(2, $image_data) ? $image_data [2] : false;
95
+			if ( ! ($image_height && $image_width)) {
96 96
 				continue;
97 97
 			}
98 98
 
99
-			if ( $image_height < 1200 || $image_width < 1200 ) {
99
+			if ($image_height < 1200 || $image_width < 1200) {
100 100
 				// Image size not present in 1200 * 1200, show a warning.
101 101
 				$recipe_with_image_warnings[] = $recipe_id;
102 102
 			}
Please login to merge, or discard this patch.
src/includes/class-wordlift-key-validation-service.php 2 patches
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -17,157 +17,157 @@
 block discarded – undo
17 17
  */
18 18
 class Wordlift_Key_Validation_Service {
19 19
 
20
-	/**
21
-	 * A {@link Wordlift_Log_Service} instance.
22
-	 *
23
-	 * @since  3.14.0
24
-	 * @access private
25
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
26
-	 */
27
-	private $log;
28
-
29
-	/**
30
-	 * The {@link Wordlift_Configuration_Service} instance.
31
-	 *
32
-	 * @since  3.14.0
33
-	 * @access private
34
-	 * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
35
-	 */
36
-	private $configuration_service;
37
-
38
-	/**
39
-	 * Create a {@link Wordlift_Key_Validation_Service} instance.
40
-	 *
41
-	 * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
42
-	 *
43
-	 * @since 3.14.0
44
-	 *
45
-	 */
46
-	public function __construct( $configuration_service ) {
47
-
48
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' );
49
-
50
-		$this->configuration_service = $configuration_service;
51
-		add_action( 'admin_init', array( $this, 'wl_load_plugin' ) );
52
-		/**
53
-		 * Filter: wl_feature__enable__notices.
54
-		 *
55
-		 * @param bool whether the notices needs to be enabled or not.
56
-		 *
57
-		 * @return bool
58
-		 * @since 3.27.6
59
-		 */
60
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
61
-			add_action( 'admin_notices', array( $this, 'wl_key_update_notice' ) );
62
-		}
63
-	}
64
-
65
-	/**
66
-	 * Validate the provided key.
67
-	 *
68
-	 * @param string $key WordLift's key to validate.
69
-	 *
70
-	 * @return WP_Error|array The response or WP_Error on failure.
71
-	 * @since 3.9.0
72
-	 *
73
-	 */
74
-	public function get_account_info( $key ) {
75
-
76
-		$this->log->debug( 'Validating key...' );
77
-
78
-		// Request the account info as a way to validate the key
79
-
80
-		$args = array_merge_recursive(
81
-			unserialize( WL_REDLINK_API_HTTP_OPTIONS ),
82
-			array(
83
-				'headers' => array(
84
-					'Content-Type'    => 'application/json; charset=utf-8',
85
-					'X-Authorization' => $key,
86
-				)
87
-			)
88
-		);
89
-
90
-		return wp_remote_get( $this->configuration_service->get_accounts_info_by_key( $key ), $args );
91
-	}
92
-
93
-	/**
94
-	 * This function is hooked to the `wl_validate_key` AJAX call.
95
-	 *
96
-	 * @since 3.9.0
97
-	 */
98
-	public function validate_key() {
99
-
100
-		// Ensure we don't have garbage before us.
101
-		ob_clean();
102
-
103
-		// Check if we have a key.
104
-		if ( ! isset( $_POST['key'] ) ) {
105
-			wp_send_json_error( 'The key parameter is required.' );
106
-		}
107
-
108
-		$response = $this->get_account_info( $_POST['key'] );
109
-
110
-		// If we got an error, return invalid.
111
-		if ( is_wp_error( $response ) || 2 !== (int) $response['response']['code'] / 100 ) {
112
-			wp_send_json_success( array( 'valid' => false, 'message' => '' ) );
113
-		}
114
-
115
-		$res_body = json_decode( wp_remote_retrieve_body( $response ), true );
116
-
117
-		// The URL stored in WLS. If this is the initial install the URL may be null.
118
-		$url = $res_body['url'];
119
-
120
-		// If the URL isn't set or matches, then it's valid.
121
-		if ( is_null( $url ) || $url === get_option( 'home' ) ) {
122
-			wp_send_json_success( array( 'valid' => true, 'message' => '' ) );
123
-		}
124
-
125
-		// If the URL doesn't match it means that this key has been configured elsewhere already.
126
-		if ( $url !== get_option( 'home' ) ) {
127
-			Wordlift_Configuration_Service::get_instance()->set_key( '' );
128
-			wp_send_json_success( array(
129
-				'valid'   => false,
130
-				'message' => __( 'The key is already used on another site, please contact us at [email protected] to move the key to another site.', 'wordlift' ),
131
-			) );
132
-		}
133
-
134
-		// Set a response with valid set to true or false according to the key validity with message.
135
-		wp_send_json_success( array(
136
-			'valid'   => false,
137
-			'message' => __( 'An error occurred, please contact us at [email protected]', 'wordlift' ),
138
-		) );
139
-	}
140
-
141
-	/**
142
-	 * This function is hooked `admin_init` to check _wl_blog_url.
143
-	 *
144
-	 */
145
-	public function wl_load_plugin() {
146
-
147
-		$wl_blog_url = get_option( '_wl_blog_url' );
148
-		$home_url    = defined( 'WP_HOME' ) ? WP_HOME : get_option( 'home' );
149
-
150
-		if ( ! $wl_blog_url ) {
151
-			update_option( '_wl_blog_url', $home_url, true );
152
-		} else if ( $wl_blog_url !== $home_url ) {
153
-			update_option( '_wl_blog_url', $home_url, true );
154
-			Wordlift_Configuration_Service::get_instance()->set_key( '' );
155
-			set_transient( 'wl-key-error-msg', __( "Your web site URL has changed. To avoid data corruption, WordLift's key has been removed. Please provide a new key in WordLift Settings. If you believe this to be an error, please contact us at [email protected]", 'wordlift' ), 10 );
156
-		}
157
-
158
-	}
159
-
160
-	/**
161
-	 * This function is hooked to the `admin_notices` to show admin notification.
162
-	 *
163
-	 */
164
-	public function wl_key_update_notice() {
165
-		if ( get_transient( 'wl-key-error-msg' ) ) {
166
-			?>
20
+    /**
21
+     * A {@link Wordlift_Log_Service} instance.
22
+     *
23
+     * @since  3.14.0
24
+     * @access private
25
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
26
+     */
27
+    private $log;
28
+
29
+    /**
30
+     * The {@link Wordlift_Configuration_Service} instance.
31
+     *
32
+     * @since  3.14.0
33
+     * @access private
34
+     * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
35
+     */
36
+    private $configuration_service;
37
+
38
+    /**
39
+     * Create a {@link Wordlift_Key_Validation_Service} instance.
40
+     *
41
+     * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance.
42
+     *
43
+     * @since 3.14.0
44
+     *
45
+     */
46
+    public function __construct( $configuration_service ) {
47
+
48
+        $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' );
49
+
50
+        $this->configuration_service = $configuration_service;
51
+        add_action( 'admin_init', array( $this, 'wl_load_plugin' ) );
52
+        /**
53
+         * Filter: wl_feature__enable__notices.
54
+         *
55
+         * @param bool whether the notices needs to be enabled or not.
56
+         *
57
+         * @return bool
58
+         * @since 3.27.6
59
+         */
60
+        if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
61
+            add_action( 'admin_notices', array( $this, 'wl_key_update_notice' ) );
62
+        }
63
+    }
64
+
65
+    /**
66
+     * Validate the provided key.
67
+     *
68
+     * @param string $key WordLift's key to validate.
69
+     *
70
+     * @return WP_Error|array The response or WP_Error on failure.
71
+     * @since 3.9.0
72
+     *
73
+     */
74
+    public function get_account_info( $key ) {
75
+
76
+        $this->log->debug( 'Validating key...' );
77
+
78
+        // Request the account info as a way to validate the key
79
+
80
+        $args = array_merge_recursive(
81
+            unserialize( WL_REDLINK_API_HTTP_OPTIONS ),
82
+            array(
83
+                'headers' => array(
84
+                    'Content-Type'    => 'application/json; charset=utf-8',
85
+                    'X-Authorization' => $key,
86
+                )
87
+            )
88
+        );
89
+
90
+        return wp_remote_get( $this->configuration_service->get_accounts_info_by_key( $key ), $args );
91
+    }
92
+
93
+    /**
94
+     * This function is hooked to the `wl_validate_key` AJAX call.
95
+     *
96
+     * @since 3.9.0
97
+     */
98
+    public function validate_key() {
99
+
100
+        // Ensure we don't have garbage before us.
101
+        ob_clean();
102
+
103
+        // Check if we have a key.
104
+        if ( ! isset( $_POST['key'] ) ) {
105
+            wp_send_json_error( 'The key parameter is required.' );
106
+        }
107
+
108
+        $response = $this->get_account_info( $_POST['key'] );
109
+
110
+        // If we got an error, return invalid.
111
+        if ( is_wp_error( $response ) || 2 !== (int) $response['response']['code'] / 100 ) {
112
+            wp_send_json_success( array( 'valid' => false, 'message' => '' ) );
113
+        }
114
+
115
+        $res_body = json_decode( wp_remote_retrieve_body( $response ), true );
116
+
117
+        // The URL stored in WLS. If this is the initial install the URL may be null.
118
+        $url = $res_body['url'];
119
+
120
+        // If the URL isn't set or matches, then it's valid.
121
+        if ( is_null( $url ) || $url === get_option( 'home' ) ) {
122
+            wp_send_json_success( array( 'valid' => true, 'message' => '' ) );
123
+        }
124
+
125
+        // If the URL doesn't match it means that this key has been configured elsewhere already.
126
+        if ( $url !== get_option( 'home' ) ) {
127
+            Wordlift_Configuration_Service::get_instance()->set_key( '' );
128
+            wp_send_json_success( array(
129
+                'valid'   => false,
130
+                'message' => __( 'The key is already used on another site, please contact us at [email protected] to move the key to another site.', 'wordlift' ),
131
+            ) );
132
+        }
133
+
134
+        // Set a response with valid set to true or false according to the key validity with message.
135
+        wp_send_json_success( array(
136
+            'valid'   => false,
137
+            'message' => __( 'An error occurred, please contact us at [email protected]', 'wordlift' ),
138
+        ) );
139
+    }
140
+
141
+    /**
142
+     * This function is hooked `admin_init` to check _wl_blog_url.
143
+     *
144
+     */
145
+    public function wl_load_plugin() {
146
+
147
+        $wl_blog_url = get_option( '_wl_blog_url' );
148
+        $home_url    = defined( 'WP_HOME' ) ? WP_HOME : get_option( 'home' );
149
+
150
+        if ( ! $wl_blog_url ) {
151
+            update_option( '_wl_blog_url', $home_url, true );
152
+        } else if ( $wl_blog_url !== $home_url ) {
153
+            update_option( '_wl_blog_url', $home_url, true );
154
+            Wordlift_Configuration_Service::get_instance()->set_key( '' );
155
+            set_transient( 'wl-key-error-msg', __( "Your web site URL has changed. To avoid data corruption, WordLift's key has been removed. Please provide a new key in WordLift Settings. If you believe this to be an error, please contact us at [email protected]", 'wordlift' ), 10 );
156
+        }
157
+
158
+    }
159
+
160
+    /**
161
+     * This function is hooked to the `admin_notices` to show admin notification.
162
+     *
163
+     */
164
+    public function wl_key_update_notice() {
165
+        if ( get_transient( 'wl-key-error-msg' ) ) {
166
+            ?>
167 167
             <div class="updated notice is-dismissible error">
168 168
                 <p><?php _e( get_transient( 'wl-key-error-msg' ), 'wordlift' ); ?></p>
169 169
             </div>
170 170
 			<?php
171
-		}
172
-	}
171
+        }
172
+    }
173 173
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -43,12 +43,12 @@  discard block
 block discarded – undo
43 43
 	 * @since 3.14.0
44 44
 	 *
45 45
 	 */
46
-	public function __construct( $configuration_service ) {
46
+	public function __construct($configuration_service) {
47 47
 
48
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Key_Validation_Service' );
48
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Key_Validation_Service');
49 49
 
50 50
 		$this->configuration_service = $configuration_service;
51
-		add_action( 'admin_init', array( $this, 'wl_load_plugin' ) );
51
+		add_action('admin_init', array($this, 'wl_load_plugin'));
52 52
 		/**
53 53
 		 * Filter: wl_feature__enable__notices.
54 54
 		 *
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
 		 * @return bool
58 58
 		 * @since 3.27.6
59 59
 		 */
60
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
61
-			add_action( 'admin_notices', array( $this, 'wl_key_update_notice' ) );
60
+		if (apply_filters('wl_feature__enable__notices', true)) {
61
+			add_action('admin_notices', array($this, 'wl_key_update_notice'));
62 62
 		}
63 63
 	}
64 64
 
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
 	 * @since 3.9.0
72 72
 	 *
73 73
 	 */
74
-	public function get_account_info( $key ) {
74
+	public function get_account_info($key) {
75 75
 
76
-		$this->log->debug( 'Validating key...' );
76
+		$this->log->debug('Validating key...');
77 77
 
78 78
 		// Request the account info as a way to validate the key
79 79
 
80 80
 		$args = array_merge_recursive(
81
-			unserialize( WL_REDLINK_API_HTTP_OPTIONS ),
81
+			unserialize(WL_REDLINK_API_HTTP_OPTIONS),
82 82
 			array(
83 83
 				'headers' => array(
84 84
 					'Content-Type'    => 'application/json; charset=utf-8',
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 			)
88 88
 		);
89 89
 
90
-		return wp_remote_get( $this->configuration_service->get_accounts_info_by_key( $key ), $args );
90
+		return wp_remote_get($this->configuration_service->get_accounts_info_by_key($key), $args);
91 91
 	}
92 92
 
93 93
 	/**
@@ -101,41 +101,41 @@  discard block
 block discarded – undo
101 101
 		ob_clean();
102 102
 
103 103
 		// Check if we have a key.
104
-		if ( ! isset( $_POST['key'] ) ) {
105
-			wp_send_json_error( 'The key parameter is required.' );
104
+		if ( ! isset($_POST['key'])) {
105
+			wp_send_json_error('The key parameter is required.');
106 106
 		}
107 107
 
108
-		$response = $this->get_account_info( $_POST['key'] );
108
+		$response = $this->get_account_info($_POST['key']);
109 109
 
110 110
 		// If we got an error, return invalid.
111
-		if ( is_wp_error( $response ) || 2 !== (int) $response['response']['code'] / 100 ) {
112
-			wp_send_json_success( array( 'valid' => false, 'message' => '' ) );
111
+		if (is_wp_error($response) || 2 !== (int) $response['response']['code'] / 100) {
112
+			wp_send_json_success(array('valid' => false, 'message' => ''));
113 113
 		}
114 114
 
115
-		$res_body = json_decode( wp_remote_retrieve_body( $response ), true );
115
+		$res_body = json_decode(wp_remote_retrieve_body($response), true);
116 116
 
117 117
 		// The URL stored in WLS. If this is the initial install the URL may be null.
118 118
 		$url = $res_body['url'];
119 119
 
120 120
 		// If the URL isn't set or matches, then it's valid.
121
-		if ( is_null( $url ) || $url === get_option( 'home' ) ) {
122
-			wp_send_json_success( array( 'valid' => true, 'message' => '' ) );
121
+		if (is_null($url) || $url === get_option('home')) {
122
+			wp_send_json_success(array('valid' => true, 'message' => ''));
123 123
 		}
124 124
 
125 125
 		// If the URL doesn't match it means that this key has been configured elsewhere already.
126
-		if ( $url !== get_option( 'home' ) ) {
127
-			Wordlift_Configuration_Service::get_instance()->set_key( '' );
128
-			wp_send_json_success( array(
126
+		if ($url !== get_option('home')) {
127
+			Wordlift_Configuration_Service::get_instance()->set_key('');
128
+			wp_send_json_success(array(
129 129
 				'valid'   => false,
130
-				'message' => __( 'The key is already used on another site, please contact us at [email protected] to move the key to another site.', 'wordlift' ),
131
-			) );
130
+				'message' => __('The key is already used on another site, please contact us at [email protected] to move the key to another site.', 'wordlift'),
131
+			));
132 132
 		}
133 133
 
134 134
 		// Set a response with valid set to true or false according to the key validity with message.
135
-		wp_send_json_success( array(
135
+		wp_send_json_success(array(
136 136
 			'valid'   => false,
137
-			'message' => __( 'An error occurred, please contact us at [email protected]', 'wordlift' ),
138
-		) );
137
+			'message' => __('An error occurred, please contact us at [email protected]', 'wordlift'),
138
+		));
139 139
 	}
140 140
 
141 141
 	/**
@@ -144,15 +144,15 @@  discard block
 block discarded – undo
144 144
 	 */
145 145
 	public function wl_load_plugin() {
146 146
 
147
-		$wl_blog_url = get_option( '_wl_blog_url' );
148
-		$home_url    = defined( 'WP_HOME' ) ? WP_HOME : get_option( 'home' );
147
+		$wl_blog_url = get_option('_wl_blog_url');
148
+		$home_url    = defined('WP_HOME') ? WP_HOME : get_option('home');
149 149
 
150
-		if ( ! $wl_blog_url ) {
151
-			update_option( '_wl_blog_url', $home_url, true );
152
-		} else if ( $wl_blog_url !== $home_url ) {
153
-			update_option( '_wl_blog_url', $home_url, true );
154
-			Wordlift_Configuration_Service::get_instance()->set_key( '' );
155
-			set_transient( 'wl-key-error-msg', __( "Your web site URL has changed. To avoid data corruption, WordLift's key has been removed. Please provide a new key in WordLift Settings. If you believe this to be an error, please contact us at [email protected]", 'wordlift' ), 10 );
150
+		if ( ! $wl_blog_url) {
151
+			update_option('_wl_blog_url', $home_url, true);
152
+		} else if ($wl_blog_url !== $home_url) {
153
+			update_option('_wl_blog_url', $home_url, true);
154
+			Wordlift_Configuration_Service::get_instance()->set_key('');
155
+			set_transient('wl-key-error-msg', __("Your web site URL has changed. To avoid data corruption, WordLift's key has been removed. Please provide a new key in WordLift Settings. If you believe this to be an error, please contact us at [email protected]", 'wordlift'), 10);
156 156
 		}
157 157
 
158 158
 	}
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
 	 *
163 163
 	 */
164 164
 	public function wl_key_update_notice() {
165
-		if ( get_transient( 'wl-key-error-msg' ) ) {
165
+		if (get_transient('wl-key-error-msg')) {
166 166
 			?>
167 167
             <div class="updated notice is-dismissible error">
168
-                <p><?php _e( get_transient( 'wl-key-error-msg' ), 'wordlift' ); ?></p>
168
+                <p><?php _e(get_transient('wl-key-error-msg'), 'wordlift'); ?></p>
169 169
             </div>
170 170
 			<?php
171 171
 		}
Please login to merge, or discard this patch.
src/admin/class-wordlift-entity-type-settings.php 2 patches
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  */
14 14
 
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -30,217 +30,217 @@  discard block
 block discarded – undo
30 30
  */
31 31
 class Wordlift_Admin_Entity_Type_Settings {
32 32
 
33
-	/**
34
-	 * A {@link Wordlift_Log_Service} instance.
35
-	 *
36
-	 * @since  3.14.0
37
-	 * @access private
38
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
39
-	 */
40
-	private $log;
41
-
42
-	/**
43
-	 * Create a {@link Wordlift_Admin_Entity_Type_Settings} instance.
44
-	 *
45
-	 * @since 3.14.0
46
-	 */
47
-	public function __construct() {
48
-
49
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Admin_Entity_Type_Settings' );
50
-
51
-	}
52
-
53
-	/**
54
-	 * Handle menu registration.
55
-	 *
56
-	 * The registration is required, although we do not want to actually to add
57
-	 * an item to the menu, in order to "whitelist" the access to the settings page in
58
-	 * the admin.
59
-	 *
60
-	 * @since 3.11.0
61
-	 */
62
-	public function admin_menu() {
63
-
64
-		/*
33
+    /**
34
+     * A {@link Wordlift_Log_Service} instance.
35
+     *
36
+     * @since  3.14.0
37
+     * @access private
38
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
39
+     */
40
+    private $log;
41
+
42
+    /**
43
+     * Create a {@link Wordlift_Admin_Entity_Type_Settings} instance.
44
+     *
45
+     * @since 3.14.0
46
+     */
47
+    public function __construct() {
48
+
49
+        $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Admin_Entity_Type_Settings' );
50
+
51
+    }
52
+
53
+    /**
54
+     * Handle menu registration.
55
+     *
56
+     * The registration is required, although we do not want to actually to add
57
+     * an item to the menu, in order to "whitelist" the access to the settings page in
58
+     * the admin.
59
+     *
60
+     * @since 3.11.0
61
+     */
62
+    public function admin_menu() {
63
+
64
+        /*
65 65
 		 * Before anything else check if an settings form was submitted.
66 66
 		 * This has to be done before any output happens in order to be able to
67 67
 		 * display proper "die" error messages and redirect.
68 68
 		 */
69
-		if ( isset( $_GET['page'] ) && ( 'wl_entity_type_settings' === $_GET['page'] ) ) {
70
-
71
-			// Validate inputs. Do not return on invalid parameters or capabilities.
72
-			$this->validate_proper_term();
73
-
74
-			// If proper form submission, handle it and redirect back to the settings page.
75
-			if ( isset( $_POST['action'] ) && ( 'wl_edit_entity_type_term' === $_POST['action'] ) ) {
76
-				$this->handle_form_submission();
77
-			}
78
-			/**
79
-			 * Filter: wl_feature__enable__notices.
80
-			 *
81
-			 * @param bool whether the notices needs to be enabled or not.
82
-			 *
83
-			 * @return bool
84
-			 * @since 3.27.6
85
-			 */
86
-			if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
87
-				// Register admin notices handler.
88
-				add_action( 'admin_notices', array( $this, 'admin_notice' ) );
89
-			}
90
-
91
-		}
92
-
93
-		/*
69
+        if ( isset( $_GET['page'] ) && ( 'wl_entity_type_settings' === $_GET['page'] ) ) {
70
+
71
+            // Validate inputs. Do not return on invalid parameters or capabilities.
72
+            $this->validate_proper_term();
73
+
74
+            // If proper form submission, handle it and redirect back to the settings page.
75
+            if ( isset( $_POST['action'] ) && ( 'wl_edit_entity_type_term' === $_POST['action'] ) ) {
76
+                $this->handle_form_submission();
77
+            }
78
+            /**
79
+             * Filter: wl_feature__enable__notices.
80
+             *
81
+             * @param bool whether the notices needs to be enabled or not.
82
+             *
83
+             * @return bool
84
+             * @since 3.27.6
85
+             */
86
+            if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
87
+                // Register admin notices handler.
88
+                add_action( 'admin_notices', array( $this, 'admin_notice' ) );
89
+            }
90
+
91
+        }
92
+
93
+        /*
94 94
 		 * Use a null parent slug to prevent the menu from actually appearing
95 95
 		 * in the admin menu.
96 96
 		 */
97
-		// @todo: use the new {@link Wordlift_Admin_Page}.
98
-		add_submenu_page(
99
-			null,
100
-			__( 'Edit Entity term', 'wordlift' ),
101
-			__( 'Edit Entity term', 'wordlift' ),
102
-			'manage_options',
103
-			'wl_entity_type_settings',
104
-			array( $this, 'render' )
105
-		);
106
-	}
107
-
108
-	/**
109
-	 * Output admin notices if needed, based on the message url parameter.
110
-	 * A value of 1 indicates that a successful save was done.
111
-	 *
112
-	 * @since 3.11.0
113
-	 */
114
-	function admin_notice() {
115
-		if ( isset( $_GET['message'] ) && ( '1' === $_GET['message'] ) ) {
116
-			?>
97
+        // @todo: use the new {@link Wordlift_Admin_Page}.
98
+        add_submenu_page(
99
+            null,
100
+            __( 'Edit Entity term', 'wordlift' ),
101
+            __( 'Edit Entity term', 'wordlift' ),
102
+            'manage_options',
103
+            'wl_entity_type_settings',
104
+            array( $this, 'render' )
105
+        );
106
+    }
107
+
108
+    /**
109
+     * Output admin notices if needed, based on the message url parameter.
110
+     * A value of 1 indicates that a successful save was done.
111
+     *
112
+     * @since 3.11.0
113
+     */
114
+    function admin_notice() {
115
+        if ( isset( $_GET['message'] ) && ( '1' === $_GET['message'] ) ) {
116
+            ?>
117 117
             <div class="notice notice-success is-dismissible">
118 118
                 <p><?php esc_html_e( 'Settings saved', 'wordlift' ) ?></p>
119 119
             </div>
120 120
 			<?php
121
-		}
122
-	}
123
-
124
-	/**
125
-	 * Validate the existence of the entity type indicated by the tag_ID url
126
-	 * parameter before doing any processing. Done before any output to mimic
127
-	 * the way WordPress handles same situation with "normal" term editing screens.
128
-	 *
129
-	 * @since 3.11.0
130
-	 */
131
-	function validate_proper_term() {
132
-
133
-		// Validate capabilities.
134
-		if ( ! current_user_can( 'manage_options' ) ) {
135
-			wp_die(
136
-				'<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
137
-				'<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>',
138
-				403
139
-			);
140
-		}
141
-
142
-		// Get the term id and the actual term.
143
-		$term_id = (int) $_REQUEST['tag_ID'];
144
-
145
-		if ( ! term_exists( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) ) {
146
-			wp_die( __( 'You attempted to edit an entity type term that doesn&#8217;t exist.', 'wordlift' ) );
147
-		}
148
-
149
-	}
150
-
151
-	/**
152
-	 * Handle the form submission of the settings form. On successful
153
-	 * handling redirect tp the setting edit page.
154
-	 *
155
-	 * @since 3.11.0
156
-	 */
157
-	function handle_form_submission() {
158
-
159
-		$term_id = (int) $_POST['tag_ID'];
160
-
161
-		// Check the nonce.
162
-		check_admin_referer( 'update-entity_type_term_' . $term_id );
163
-
164
-		$term = get_term( $term_id, 'wl_entity_type' );
165
-
166
-		$this->set_setting(
167
-			$term_id,
168
-			trim( wp_unslash( $_POST['title'] ) ),
169
-			wp_unslash( $_POST['description'] )
170
-		);
171
-
172
-		// Redirect back to the term settings page and indicate a save was done.
173
-		$url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1" );
174
-
175
-		wp_redirect( $url );
176
-		exit;
177
-
178
-	}
179
-
180
-	/**
181
-	 * Render the settings page for the term.
182
-	 *
183
-	 * Access and parameter validity is assumed to be done earlier.
184
-	 *
185
-	 * @since 3.11.0
186
-	 */
187
-	function render() {
188
-
189
-		// Set variables used by the partial
190
-		$term_id  = absint( $_REQUEST['tag_ID'] );
191
-		$settings = $this->get_setting( $term_id );
192
-
193
-		include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-entity-type-settings.php';
194
-
195
-	}
196
-
197
-	/**
198
-	 * Store the entity type term settings in the DB
199
-	 *
200
-	 * @param integer $term_id The ID of the entity type term
201
-	 * @param string $title The override for the terms title.
202
-	 * @param string $description The override for the terms description.
203
-	 *
204
-	 * @since 3.11.0
205
-	 *
206
-	 */
207
-	function set_setting( $term_id, $title, $description ) {
208
-
209
-		$settings             = get_option( 'wl_entity_type_settings', array() );
210
-		$settings[ $term_id ] = array(
211
-			'title'       => $title,
212
-			'description' => $description,
213
-		);
214
-		update_option( 'wl_entity_type_settings', $settings );
215
-
216
-	}
217
-
218
-	/**
219
-	 * Retrieve the entity type term settings from the DB
220
-	 *
221
-	 * @param integer $term_id The ID of the entity type term
222
-	 *
223
-	 * @return    null|array {
224
-	 *                null is returned when there are no settings otherwise
225
-	 *                an array is returned with following fields
226
-	 *
227
-	 * @type    string    title    The overriding title for the term
228
-	 * @type    string    description    The overriding description for the term
229
-	 *            }
230
-	 * @since 3.11.0
231
-	 *
232
-	 */
233
-	function get_setting( $term_id ) {
234
-
235
-		$settings = get_option( 'wl_entity_type_settings', array() );
236
-
237
-		if ( isset( $settings[ $term_id ] ) ) {
238
-			return $settings[ $term_id ];
239
-		}
240
-
241
-		$this->log->warn( "No settings found for term id $term_id." );
242
-
243
-		return null;
244
-	}
121
+        }
122
+    }
123
+
124
+    /**
125
+     * Validate the existence of the entity type indicated by the tag_ID url
126
+     * parameter before doing any processing. Done before any output to mimic
127
+     * the way WordPress handles same situation with "normal" term editing screens.
128
+     *
129
+     * @since 3.11.0
130
+     */
131
+    function validate_proper_term() {
132
+
133
+        // Validate capabilities.
134
+        if ( ! current_user_can( 'manage_options' ) ) {
135
+            wp_die(
136
+                '<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
137
+                '<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>',
138
+                403
139
+            );
140
+        }
141
+
142
+        // Get the term id and the actual term.
143
+        $term_id = (int) $_REQUEST['tag_ID'];
144
+
145
+        if ( ! term_exists( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) ) {
146
+            wp_die( __( 'You attempted to edit an entity type term that doesn&#8217;t exist.', 'wordlift' ) );
147
+        }
148
+
149
+    }
150
+
151
+    /**
152
+     * Handle the form submission of the settings form. On successful
153
+     * handling redirect tp the setting edit page.
154
+     *
155
+     * @since 3.11.0
156
+     */
157
+    function handle_form_submission() {
158
+
159
+        $term_id = (int) $_POST['tag_ID'];
160
+
161
+        // Check the nonce.
162
+        check_admin_referer( 'update-entity_type_term_' . $term_id );
163
+
164
+        $term = get_term( $term_id, 'wl_entity_type' );
165
+
166
+        $this->set_setting(
167
+            $term_id,
168
+            trim( wp_unslash( $_POST['title'] ) ),
169
+            wp_unslash( $_POST['description'] )
170
+        );
171
+
172
+        // Redirect back to the term settings page and indicate a save was done.
173
+        $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1" );
174
+
175
+        wp_redirect( $url );
176
+        exit;
177
+
178
+    }
179
+
180
+    /**
181
+     * Render the settings page for the term.
182
+     *
183
+     * Access and parameter validity is assumed to be done earlier.
184
+     *
185
+     * @since 3.11.0
186
+     */
187
+    function render() {
188
+
189
+        // Set variables used by the partial
190
+        $term_id  = absint( $_REQUEST['tag_ID'] );
191
+        $settings = $this->get_setting( $term_id );
192
+
193
+        include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-entity-type-settings.php';
194
+
195
+    }
196
+
197
+    /**
198
+     * Store the entity type term settings in the DB
199
+     *
200
+     * @param integer $term_id The ID of the entity type term
201
+     * @param string $title The override for the terms title.
202
+     * @param string $description The override for the terms description.
203
+     *
204
+     * @since 3.11.0
205
+     *
206
+     */
207
+    function set_setting( $term_id, $title, $description ) {
208
+
209
+        $settings             = get_option( 'wl_entity_type_settings', array() );
210
+        $settings[ $term_id ] = array(
211
+            'title'       => $title,
212
+            'description' => $description,
213
+        );
214
+        update_option( 'wl_entity_type_settings', $settings );
215
+
216
+    }
217
+
218
+    /**
219
+     * Retrieve the entity type term settings from the DB
220
+     *
221
+     * @param integer $term_id The ID of the entity type term
222
+     *
223
+     * @return    null|array {
224
+     *                null is returned when there are no settings otherwise
225
+     *                an array is returned with following fields
226
+     *
227
+     * @type    string    title    The overriding title for the term
228
+     * @type    string    description    The overriding description for the term
229
+     *            }
230
+     * @since 3.11.0
231
+     *
232
+     */
233
+    function get_setting( $term_id ) {
234
+
235
+        $settings = get_option( 'wl_entity_type_settings', array() );
236
+
237
+        if ( isset( $settings[ $term_id ] ) ) {
238
+            return $settings[ $term_id ];
239
+        }
240
+
241
+        $this->log->warn( "No settings found for term id $term_id." );
242
+
243
+        return null;
244
+    }
245 245
 
246 246
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @since      3.11.0
13 13
  */
14 14
 
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 */
47 47
 	public function __construct() {
48 48
 
49
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Admin_Entity_Type_Settings' );
49
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Admin_Entity_Type_Settings');
50 50
 
51 51
 	}
52 52
 
@@ -66,13 +66,13 @@  discard block
 block discarded – undo
66 66
 		 * This has to be done before any output happens in order to be able to
67 67
 		 * display proper "die" error messages and redirect.
68 68
 		 */
69
-		if ( isset( $_GET['page'] ) && ( 'wl_entity_type_settings' === $_GET['page'] ) ) {
69
+		if (isset($_GET['page']) && ('wl_entity_type_settings' === $_GET['page'])) {
70 70
 
71 71
 			// Validate inputs. Do not return on invalid parameters or capabilities.
72 72
 			$this->validate_proper_term();
73 73
 
74 74
 			// If proper form submission, handle it and redirect back to the settings page.
75
-			if ( isset( $_POST['action'] ) && ( 'wl_edit_entity_type_term' === $_POST['action'] ) ) {
75
+			if (isset($_POST['action']) && ('wl_edit_entity_type_term' === $_POST['action'])) {
76 76
 				$this->handle_form_submission();
77 77
 			}
78 78
 			/**
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
 			 * @return bool
84 84
 			 * @since 3.27.6
85 85
 			 */
86
-			if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
86
+			if (apply_filters('wl_feature__enable__notices', true)) {
87 87
 				// Register admin notices handler.
88
-				add_action( 'admin_notices', array( $this, 'admin_notice' ) );
88
+				add_action('admin_notices', array($this, 'admin_notice'));
89 89
 			}
90 90
 
91 91
 		}
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 		// @todo: use the new {@link Wordlift_Admin_Page}.
98 98
 		add_submenu_page(
99 99
 			null,
100
-			__( 'Edit Entity term', 'wordlift' ),
101
-			__( 'Edit Entity term', 'wordlift' ),
100
+			__('Edit Entity term', 'wordlift'),
101
+			__('Edit Entity term', 'wordlift'),
102 102
 			'manage_options',
103 103
 			'wl_entity_type_settings',
104
-			array( $this, 'render' )
104
+			array($this, 'render')
105 105
 		);
106 106
 	}
107 107
 
@@ -112,10 +112,10 @@  discard block
 block discarded – undo
112 112
 	 * @since 3.11.0
113 113
 	 */
114 114
 	function admin_notice() {
115
-		if ( isset( $_GET['message'] ) && ( '1' === $_GET['message'] ) ) {
115
+		if (isset($_GET['message']) && ('1' === $_GET['message'])) {
116 116
 			?>
117 117
             <div class="notice notice-success is-dismissible">
118
-                <p><?php esc_html_e( 'Settings saved', 'wordlift' ) ?></p>
118
+                <p><?php esc_html_e('Settings saved', 'wordlift') ?></p>
119 119
             </div>
120 120
 			<?php
121 121
 		}
@@ -131,10 +131,10 @@  discard block
 block discarded – undo
131 131
 	function validate_proper_term() {
132 132
 
133 133
 		// Validate capabilities.
134
-		if ( ! current_user_can( 'manage_options' ) ) {
134
+		if ( ! current_user_can('manage_options')) {
135 135
 			wp_die(
136
-				'<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
137
-				'<p>' . __( 'Sorry, you are not allowed to edit this item.' ) . '</p>',
136
+				'<h1>'.__('Cheatin&#8217; uh?').'</h1>'.
137
+				'<p>'.__('Sorry, you are not allowed to edit this item.').'</p>',
138 138
 				403
139 139
 			);
140 140
 		}
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
 		// Get the term id and the actual term.
143 143
 		$term_id = (int) $_REQUEST['tag_ID'];
144 144
 
145
-		if ( ! term_exists( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) ) {
146
-			wp_die( __( 'You attempted to edit an entity type term that doesn&#8217;t exist.', 'wordlift' ) );
145
+		if ( ! term_exists($term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME)) {
146
+			wp_die(__('You attempted to edit an entity type term that doesn&#8217;t exist.', 'wordlift'));
147 147
 		}
148 148
 
149 149
 	}
@@ -159,20 +159,20 @@  discard block
 block discarded – undo
159 159
 		$term_id = (int) $_POST['tag_ID'];
160 160
 
161 161
 		// Check the nonce.
162
-		check_admin_referer( 'update-entity_type_term_' . $term_id );
162
+		check_admin_referer('update-entity_type_term_'.$term_id);
163 163
 
164
-		$term = get_term( $term_id, 'wl_entity_type' );
164
+		$term = get_term($term_id, 'wl_entity_type');
165 165
 
166 166
 		$this->set_setting(
167 167
 			$term_id,
168
-			trim( wp_unslash( $_POST['title'] ) ),
169
-			wp_unslash( $_POST['description'] )
168
+			trim(wp_unslash($_POST['title'])),
169
+			wp_unslash($_POST['description'])
170 170
 		);
171 171
 
172 172
 		// Redirect back to the term settings page and indicate a save was done.
173
-		$url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1" );
173
+		$url = admin_url("admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id&message=1");
174 174
 
175
-		wp_redirect( $url );
175
+		wp_redirect($url);
176 176
 		exit;
177 177
 
178 178
 	}
@@ -187,10 +187,10 @@  discard block
 block discarded – undo
187 187
 	function render() {
188 188
 
189 189
 		// Set variables used by the partial
190
-		$term_id  = absint( $_REQUEST['tag_ID'] );
191
-		$settings = $this->get_setting( $term_id );
190
+		$term_id  = absint($_REQUEST['tag_ID']);
191
+		$settings = $this->get_setting($term_id);
192 192
 
193
-		include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-entity-type-settings.php';
193
+		include plugin_dir_path(dirname(__FILE__)).'admin/partials/wordlift-admin-entity-type-settings.php';
194 194
 
195 195
 	}
196 196
 
@@ -204,14 +204,14 @@  discard block
 block discarded – undo
204 204
 	 * @since 3.11.0
205 205
 	 *
206 206
 	 */
207
-	function set_setting( $term_id, $title, $description ) {
207
+	function set_setting($term_id, $title, $description) {
208 208
 
209
-		$settings             = get_option( 'wl_entity_type_settings', array() );
210
-		$settings[ $term_id ] = array(
209
+		$settings             = get_option('wl_entity_type_settings', array());
210
+		$settings[$term_id] = array(
211 211
 			'title'       => $title,
212 212
 			'description' => $description,
213 213
 		);
214
-		update_option( 'wl_entity_type_settings', $settings );
214
+		update_option('wl_entity_type_settings', $settings);
215 215
 
216 216
 	}
217 217
 
@@ -230,15 +230,15 @@  discard block
 block discarded – undo
230 230
 	 * @since 3.11.0
231 231
 	 *
232 232
 	 */
233
-	function get_setting( $term_id ) {
233
+	function get_setting($term_id) {
234 234
 
235
-		$settings = get_option( 'wl_entity_type_settings', array() );
235
+		$settings = get_option('wl_entity_type_settings', array());
236 236
 
237
-		if ( isset( $settings[ $term_id ] ) ) {
238
-			return $settings[ $term_id ];
237
+		if (isset($settings[$term_id])) {
238
+			return $settings[$term_id];
239 239
 		}
240 240
 
241
-		$this->log->warn( "No settings found for term id $term_id." );
241
+		$this->log->warn("No settings found for term id $term_id.");
242 242
 
243 243
 		return null;
244 244
 	}
Please login to merge, or discard this patch.
src/admin/class-wordlift-notice-service.php 2 patches
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -7,194 +7,194 @@
 block discarded – undo
7 7
  */
8 8
 class Wordlift_Notice_Service {
9 9
 
10
-	/**
11
-	 * The template used to display notices. The <em>notice dismissible</em> style classes make this notice dismissible
12
-	 * on the WordPress UI (via a small X button on the right side of the notice).
13
-	 *
14
-	 * @since 3.2.0
15
-	 */
16
-	const TEMPLATE = '<div class="wl-notice notice is-dismissible %s"><p>%s</p></div>';
17
-
18
-	/**
19
-	 * The standard WordPress <em>update</em> style class.
20
-	 *
21
-	 * @since 3.2.0
22
-	 */
23
-	const UPDATE = 'update';
24
-
25
-	/**
26
-	 * The standard WordPress <em>update-nag</em> style class.
27
-	 *
28
-	 * @since 3.2.0
29
-	 */
30
-	const UPDATE_NAG = 'update-nag';
31
-
32
-	/**
33
-	 * The standard WordPress <em>error</em> style class.
34
-	 *
35
-	 * @since 3.2.0
36
-	 */
37
-	const ERROR = 'error';
38
-
39
-	/**
40
-	 * A custom WordLift css style class used for WordLift suggestions.
41
-	 *
42
-	 * @since 3.3.0
43
-	 */
44
-	const SUGGESTION = 'wl-suggestion';
45
-
46
-	/**
47
-	 * The array of notices.
48
-	 *
49
-	 * @since 3.2.0
50
-	 * @access private
51
-	 * @var array $notices The array of notices.
52
-	 */
53
-	private $notices = array();
54
-
55
-	/**
56
-	 * A singleton instance of the Notice service.
57
-	 *
58
-	 * @since 3.2.0
59
-	 * @access private
60
-	 * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service.
61
-	 */
62
-	private static $instance;
63
-
64
-	/**
65
-	 * Create an instance of the Notice service.
66
-	 *
67
-	 * @since 3.2.0
68
-	 */
69
-	public function __construct() {
70
-		/**
71
-		 * Filter: wl_feature__enable__notices.
72
-		 *
73
-		 * @param bool whether the notices needs to be enabled or not.
74
-		 *
75
-		 * @return bool
76
-		 * @since 3.27.6
77
-		 */
78
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
79
-			// Hook to be called when to display notices.
80
-			add_action( 'admin_notices', array( $this, 'admin_notices' ) );
81
-		}
82
-		self::$instance = $this;
83
-
84
-	}
85
-
86
-	/**
87
-	 * Get the singleton instance of the Notice service.
88
-	 *
89
-	 * @return \Wordlift_Notice_Service The singleton instance of the Notice service.
90
-	 * @since 3.2.0
91
-	 */
92
-	public static function get_instance() {
93
-
94
-		return self::$instance;
95
-	}
96
-
97
-	/**
98
-	 * Add a notice.
99
-	 *
100
-	 * @param string $class The css class.
101
-	 * @param string $message The message.
102
-	 *
103
-	 * @since 3.2.0
104
-	 *
105
-	 */
106
-	public function add( $class, $message ) {
107
-
108
-		$this->notices[] = sprintf( self::TEMPLATE, $class, $this->transform( $message ) );
109
-
110
-	}
111
-
112
-	/**
113
-	 * Add an update notice (message with a white background and a green left border).
114
-	 *
115
-	 * @param string $message The message to display.
116
-	 *
117
-	 * @since 3.2.0
118
-	 *
119
-	 */
120
-	public function add_update( $message ) {
121
-
122
-		$this->add( self::UPDATE, $message );
123
-
124
-	}
125
-
126
-	/**
127
-	 * Add an update nag notice (message with a white background and a yellow left border).
128
-	 *
129
-	 * @param string $message The message to display.
130
-	 *
131
-	 * @since 3.2.0
132
-	 *
133
-	 */
134
-	public function add_update_nag( $message ) {
135
-
136
-		$this->add( self::UPDATE_NAG, $message );
137
-
138
-	}
139
-
140
-	/**
141
-	 * Add an error notice (message with a white background and a red left border).
142
-	 *
143
-	 * @param string $message The message to display.
144
-	 *
145
-	 * @since 3.2.0
146
-	 *
147
-	 */
148
-	public function add_error( $message ) {
149
-
150
-		$this->add( self::ERROR, $message );
151
-
152
-	}
153
-
154
-	/**
155
-	 * Add a suggestion notice (message with a white background and a WordLift brand colored left border).
156
-	 *
157
-	 * @param string $message The message to display.
158
-	 *
159
-	 * @since 3.3.0
160
-	 *
161
-	 */
162
-	public function add_suggestion( $message ) {
163
-
164
-		$this->add( self::SUGGESTION, $message );
165
-
166
-	}
167
-
168
-	/**
169
-	 * Print out the notices when the admin_notices action is called.
170
-	 *
171
-	 * @since 3.2.0
172
-	 */
173
-	public function admin_notices() {
174
-
175
-		foreach ( $this->notices as $notice ) {
176
-			echo( $notice );
177
-		}
178
-
179
-	}
180
-
181
-	/**
182
-	 * Transform message depending on message type. Return a string
183
-	 *
184
-	 * @param string $message The message.
185
-	 *
186
-	 * @since 3.3.0
187
-	 *
188
-	 */
189
-	private function transform( $message ) {
190
-
191
-		switch ( gettype( $message ) ) {
192
-			case 'array':
193
-				return implode( $message, '<br />' );
194
-			default:
195
-				return $message;
196
-		}
197
-
198
-	}
10
+    /**
11
+     * The template used to display notices. The <em>notice dismissible</em> style classes make this notice dismissible
12
+     * on the WordPress UI (via a small X button on the right side of the notice).
13
+     *
14
+     * @since 3.2.0
15
+     */
16
+    const TEMPLATE = '<div class="wl-notice notice is-dismissible %s"><p>%s</p></div>';
17
+
18
+    /**
19
+     * The standard WordPress <em>update</em> style class.
20
+     *
21
+     * @since 3.2.0
22
+     */
23
+    const UPDATE = 'update';
24
+
25
+    /**
26
+     * The standard WordPress <em>update-nag</em> style class.
27
+     *
28
+     * @since 3.2.0
29
+     */
30
+    const UPDATE_NAG = 'update-nag';
31
+
32
+    /**
33
+     * The standard WordPress <em>error</em> style class.
34
+     *
35
+     * @since 3.2.0
36
+     */
37
+    const ERROR = 'error';
38
+
39
+    /**
40
+     * A custom WordLift css style class used for WordLift suggestions.
41
+     *
42
+     * @since 3.3.0
43
+     */
44
+    const SUGGESTION = 'wl-suggestion';
45
+
46
+    /**
47
+     * The array of notices.
48
+     *
49
+     * @since 3.2.0
50
+     * @access private
51
+     * @var array $notices The array of notices.
52
+     */
53
+    private $notices = array();
54
+
55
+    /**
56
+     * A singleton instance of the Notice service.
57
+     *
58
+     * @since 3.2.0
59
+     * @access private
60
+     * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service.
61
+     */
62
+    private static $instance;
63
+
64
+    /**
65
+     * Create an instance of the Notice service.
66
+     *
67
+     * @since 3.2.0
68
+     */
69
+    public function __construct() {
70
+        /**
71
+         * Filter: wl_feature__enable__notices.
72
+         *
73
+         * @param bool whether the notices needs to be enabled or not.
74
+         *
75
+         * @return bool
76
+         * @since 3.27.6
77
+         */
78
+        if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
79
+            // Hook to be called when to display notices.
80
+            add_action( 'admin_notices', array( $this, 'admin_notices' ) );
81
+        }
82
+        self::$instance = $this;
83
+
84
+    }
85
+
86
+    /**
87
+     * Get the singleton instance of the Notice service.
88
+     *
89
+     * @return \Wordlift_Notice_Service The singleton instance of the Notice service.
90
+     * @since 3.2.0
91
+     */
92
+    public static function get_instance() {
93
+
94
+        return self::$instance;
95
+    }
96
+
97
+    /**
98
+     * Add a notice.
99
+     *
100
+     * @param string $class The css class.
101
+     * @param string $message The message.
102
+     *
103
+     * @since 3.2.0
104
+     *
105
+     */
106
+    public function add( $class, $message ) {
107
+
108
+        $this->notices[] = sprintf( self::TEMPLATE, $class, $this->transform( $message ) );
109
+
110
+    }
111
+
112
+    /**
113
+     * Add an update notice (message with a white background and a green left border).
114
+     *
115
+     * @param string $message The message to display.
116
+     *
117
+     * @since 3.2.0
118
+     *
119
+     */
120
+    public function add_update( $message ) {
121
+
122
+        $this->add( self::UPDATE, $message );
123
+
124
+    }
125
+
126
+    /**
127
+     * Add an update nag notice (message with a white background and a yellow left border).
128
+     *
129
+     * @param string $message The message to display.
130
+     *
131
+     * @since 3.2.0
132
+     *
133
+     */
134
+    public function add_update_nag( $message ) {
135
+
136
+        $this->add( self::UPDATE_NAG, $message );
137
+
138
+    }
139
+
140
+    /**
141
+     * Add an error notice (message with a white background and a red left border).
142
+     *
143
+     * @param string $message The message to display.
144
+     *
145
+     * @since 3.2.0
146
+     *
147
+     */
148
+    public function add_error( $message ) {
149
+
150
+        $this->add( self::ERROR, $message );
151
+
152
+    }
153
+
154
+    /**
155
+     * Add a suggestion notice (message with a white background and a WordLift brand colored left border).
156
+     *
157
+     * @param string $message The message to display.
158
+     *
159
+     * @since 3.3.0
160
+     *
161
+     */
162
+    public function add_suggestion( $message ) {
163
+
164
+        $this->add( self::SUGGESTION, $message );
165
+
166
+    }
167
+
168
+    /**
169
+     * Print out the notices when the admin_notices action is called.
170
+     *
171
+     * @since 3.2.0
172
+     */
173
+    public function admin_notices() {
174
+
175
+        foreach ( $this->notices as $notice ) {
176
+            echo( $notice );
177
+        }
178
+
179
+    }
180
+
181
+    /**
182
+     * Transform message depending on message type. Return a string
183
+     *
184
+     * @param string $message The message.
185
+     *
186
+     * @since 3.3.0
187
+     *
188
+     */
189
+    private function transform( $message ) {
190
+
191
+        switch ( gettype( $message ) ) {
192
+            case 'array':
193
+                return implode( $message, '<br />' );
194
+            default:
195
+                return $message;
196
+        }
197
+
198
+    }
199 199
 
200 200
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
 		 * @return bool
76 76
 		 * @since 3.27.6
77 77
 		 */
78
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
78
+		if (apply_filters('wl_feature__enable__notices', true)) {
79 79
 			// Hook to be called when to display notices.
80
-			add_action( 'admin_notices', array( $this, 'admin_notices' ) );
80
+			add_action('admin_notices', array($this, 'admin_notices'));
81 81
 		}
82 82
 		self::$instance = $this;
83 83
 
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
 	 * @since 3.2.0
104 104
 	 *
105 105
 	 */
106
-	public function add( $class, $message ) {
106
+	public function add($class, $message) {
107 107
 
108
-		$this->notices[] = sprintf( self::TEMPLATE, $class, $this->transform( $message ) );
108
+		$this->notices[] = sprintf(self::TEMPLATE, $class, $this->transform($message));
109 109
 
110 110
 	}
111 111
 
@@ -117,9 +117,9 @@  discard block
 block discarded – undo
117 117
 	 * @since 3.2.0
118 118
 	 *
119 119
 	 */
120
-	public function add_update( $message ) {
120
+	public function add_update($message) {
121 121
 
122
-		$this->add( self::UPDATE, $message );
122
+		$this->add(self::UPDATE, $message);
123 123
 
124 124
 	}
125 125
 
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 	 * @since 3.2.0
132 132
 	 *
133 133
 	 */
134
-	public function add_update_nag( $message ) {
134
+	public function add_update_nag($message) {
135 135
 
136
-		$this->add( self::UPDATE_NAG, $message );
136
+		$this->add(self::UPDATE_NAG, $message);
137 137
 
138 138
 	}
139 139
 
@@ -145,9 +145,9 @@  discard block
 block discarded – undo
145 145
 	 * @since 3.2.0
146 146
 	 *
147 147
 	 */
148
-	public function add_error( $message ) {
148
+	public function add_error($message) {
149 149
 
150
-		$this->add( self::ERROR, $message );
150
+		$this->add(self::ERROR, $message);
151 151
 
152 152
 	}
153 153
 
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
 	 * @since 3.3.0
160 160
 	 *
161 161
 	 */
162
-	public function add_suggestion( $message ) {
162
+	public function add_suggestion($message) {
163 163
 
164
-		$this->add( self::SUGGESTION, $message );
164
+		$this->add(self::SUGGESTION, $message);
165 165
 
166 166
 	}
167 167
 
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
 	 */
173 173
 	public function admin_notices() {
174 174
 
175
-		foreach ( $this->notices as $notice ) {
176
-			echo( $notice );
175
+		foreach ($this->notices as $notice) {
176
+			echo($notice);
177 177
 		}
178 178
 
179 179
 	}
@@ -186,11 +186,11 @@  discard block
 block discarded – undo
186 186
 	 * @since 3.3.0
187 187
 	 *
188 188
 	 */
189
-	private function transform( $message ) {
189
+	private function transform($message) {
190 190
 
191
-		switch ( gettype( $message ) ) {
191
+		switch (gettype($message)) {
192 192
 			case 'array':
193
-				return implode( $message, '<br />' );
193
+				return implode($message, '<br />');
194 194
 			default:
195 195
 				return $message;
196 196
 		}
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-setup.php 2 patches
Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  */
14 14
 
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -28,148 +28,148 @@  discard block
 block discarded – undo
28 28
  */
29 29
 class Wordlift_Admin_Setup {
30 30
 
31
-	/**
32
-	 * A {@link Wordlift_Configuration_Service} instance.
33
-	 *
34
-	 * @since  3.9.0
35
-	 * @access private
36
-	 * @var Wordlift_Configuration_Service A {@link Wordlift_Configuration_Service} instance.
37
-	 */
38
-	private $configuration_service;
39
-
40
-	/**
41
-	 * A {@link Wordlift_Key_Validation_Service} instance.
42
-	 *
43
-	 * @since  3.9.0
44
-	 * @access private
45
-	 * @var Wordlift_Key_Validation_Service A {@link Wordlift_Key_Validation_Service} instance.
46
-	 */
47
-	private $key_validation_service;
48
-
49
-	/**
50
-	 * A {@link Wordlift_Entity_Service} instance.
51
-	 *
52
-	 * @since  3.9.0
53
-	 * @access private
54
-	 * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
55
-	 */
56
-	private $entity_service;
57
-
58
-	/**
59
-	 * A {@link Wordlift_Admin_Language_Select_Element} element renderer.
60
-	 *
61
-	 * @since  3.20.0
62
-	 * @access private
63
-	 * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
64
-	 */
65
-	private $language_select_element;
66
-
67
-	/**
68
-	 * A {@link Wordlift_Admin_Country_Select_Element} element renderer.
69
-	 *
70
-	 * @since  3.20.0
71
-	 * @access private
72
-	 * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer.
73
-	 */
74
-	private $country_select_element;
75
-
76
-	/**
77
-	 * Initialize the class and set its properties.
78
-	 *
79
-	 * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance.
80
-	 * @param \Wordlift_Key_Validation_Service $key_validation_service A {@link Wordlift_Key_Validation_Service} instance.
81
-	 * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
82
-	 * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
83
-	 * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer.
84
-	 *
85
-	 * @since    3.9.0
86
-	 *
87
-	 */
88
-	public function __construct( $configuration_service, $key_validation_service, $entity_service, $language_select_element, $country_select_element ) {
89
-
90
-		// Set a reference to the configuration service.
91
-		$this->configuration_service = $configuration_service;
92
-
93
-		// Set a reference to the key validation service.
94
-		$this->key_validation_service = $key_validation_service;
95
-
96
-		// Set a reference to the entity service.
97
-		$this->entity_service = $entity_service;
98
-
99
-		// Set a reference to the UI elements language and country.
100
-		$this->language_select_element = $language_select_element;
101
-		$this->country_select_element  = $country_select_element;
102
-
103
-		// Hook to some WP's events:
104
-		// When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up.
105
-		add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
106
-
107
-		// Hook to `admin_menu` in order to add our own setup wizard page.
108
-		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
109
-
110
-
111
-		/**
112
-		 * Filter: wl_feature__enable__setup_screen.
113
-		 *
114
-		 * @param bool whether the setup screen needs to be shown or not, default to true.
115
-		 *
116
-		 * @return bool
117
-		 * @since 3.27.6
118
-		 */
119
-		if ( apply_filters( 'wl_feature__enable__setup_screen', true ) ) {
120
-			// Triggered when the user accesses the admin area, we decide whether to show our own wizard.
121
-			add_action( 'admin_init', array( $this, 'show_page' ) );
122
-		}
123
-		/**
124
-		 * Filter: wl_feature__enable__notices.
125
-		 * @param bool whether the notices needs to be enabled or not.
126
-		 * @return bool
127
-		 * @since 3.27.6
128
-		 */
129
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
130
-			// Hook to `admin_notices` to display our notices.
131
-			add_action( 'admin_notices', array( $this, 'admin_notices' ) );
132
-		}
133
-	}
134
-
135
-	/**
136
-	 * Hook to `admin_init` and redirect to WordLift's setup page if the `_wl_activation_redirect` transient flag is set.
137
-	 *
138
-	 * @since 3.9.0
139
-	 */
140
-	public function admin_init() {
141
-
142
-		// If the `_wl_activation_redirect` is set, the redirect to the setup page.
143
-		if ( get_transient( '_wl_activation_redirect' ) ) {
144
-			delete_transient( '_wl_activation_redirect' );
145
-
146
-			// If the user asked to skip the wizard then comply.
147
-			if ( $this->configuration_service->is_skip_wizard() ) {
148
-				return;
149
-			}
150
-
151
-			// If we're already on the page or the user doesn't have permissions, return.
152
-			if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) {
153
-				return;
154
-			}
155
-
156
-			// Finally redirect to the setup page.
157
-			wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) );
158
-
159
-			exit;
160
-		}
161
-
162
-	}
163
-
164
-	/**
165
-	 * Generate an admin notice suggesting to start the wizard if there is no configuration.
166
-	 *
167
-	 * @since    3.9.0
168
-	 */
169
-	public function admin_notices() {
170
-
171
-		// Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard.
172
-		if ( '' === $this->configuration_service->get_key() && ! $this->configuration_service->is_skip_wizard() ) { ?>
31
+    /**
32
+     * A {@link Wordlift_Configuration_Service} instance.
33
+     *
34
+     * @since  3.9.0
35
+     * @access private
36
+     * @var Wordlift_Configuration_Service A {@link Wordlift_Configuration_Service} instance.
37
+     */
38
+    private $configuration_service;
39
+
40
+    /**
41
+     * A {@link Wordlift_Key_Validation_Service} instance.
42
+     *
43
+     * @since  3.9.0
44
+     * @access private
45
+     * @var Wordlift_Key_Validation_Service A {@link Wordlift_Key_Validation_Service} instance.
46
+     */
47
+    private $key_validation_service;
48
+
49
+    /**
50
+     * A {@link Wordlift_Entity_Service} instance.
51
+     *
52
+     * @since  3.9.0
53
+     * @access private
54
+     * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
55
+     */
56
+    private $entity_service;
57
+
58
+    /**
59
+     * A {@link Wordlift_Admin_Language_Select_Element} element renderer.
60
+     *
61
+     * @since  3.20.0
62
+     * @access private
63
+     * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
64
+     */
65
+    private $language_select_element;
66
+
67
+    /**
68
+     * A {@link Wordlift_Admin_Country_Select_Element} element renderer.
69
+     *
70
+     * @since  3.20.0
71
+     * @access private
72
+     * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer.
73
+     */
74
+    private $country_select_element;
75
+
76
+    /**
77
+     * Initialize the class and set its properties.
78
+     *
79
+     * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance.
80
+     * @param \Wordlift_Key_Validation_Service $key_validation_service A {@link Wordlift_Key_Validation_Service} instance.
81
+     * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
82
+     * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer.
83
+     * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer.
84
+     *
85
+     * @since    3.9.0
86
+     *
87
+     */
88
+    public function __construct( $configuration_service, $key_validation_service, $entity_service, $language_select_element, $country_select_element ) {
89
+
90
+        // Set a reference to the configuration service.
91
+        $this->configuration_service = $configuration_service;
92
+
93
+        // Set a reference to the key validation service.
94
+        $this->key_validation_service = $key_validation_service;
95
+
96
+        // Set a reference to the entity service.
97
+        $this->entity_service = $entity_service;
98
+
99
+        // Set a reference to the UI elements language and country.
100
+        $this->language_select_element = $language_select_element;
101
+        $this->country_select_element  = $country_select_element;
102
+
103
+        // Hook to some WP's events:
104
+        // When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up.
105
+        add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
106
+
107
+        // Hook to `admin_menu` in order to add our own setup wizard page.
108
+        add_action( 'admin_menu', array( $this, 'admin_menu' ) );
109
+
110
+
111
+        /**
112
+         * Filter: wl_feature__enable__setup_screen.
113
+         *
114
+         * @param bool whether the setup screen needs to be shown or not, default to true.
115
+         *
116
+         * @return bool
117
+         * @since 3.27.6
118
+         */
119
+        if ( apply_filters( 'wl_feature__enable__setup_screen', true ) ) {
120
+            // Triggered when the user accesses the admin area, we decide whether to show our own wizard.
121
+            add_action( 'admin_init', array( $this, 'show_page' ) );
122
+        }
123
+        /**
124
+         * Filter: wl_feature__enable__notices.
125
+         * @param bool whether the notices needs to be enabled or not.
126
+         * @return bool
127
+         * @since 3.27.6
128
+         */
129
+        if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
130
+            // Hook to `admin_notices` to display our notices.
131
+            add_action( 'admin_notices', array( $this, 'admin_notices' ) );
132
+        }
133
+    }
134
+
135
+    /**
136
+     * Hook to `admin_init` and redirect to WordLift's setup page if the `_wl_activation_redirect` transient flag is set.
137
+     *
138
+     * @since 3.9.0
139
+     */
140
+    public function admin_init() {
141
+
142
+        // If the `_wl_activation_redirect` is set, the redirect to the setup page.
143
+        if ( get_transient( '_wl_activation_redirect' ) ) {
144
+            delete_transient( '_wl_activation_redirect' );
145
+
146
+            // If the user asked to skip the wizard then comply.
147
+            if ( $this->configuration_service->is_skip_wizard() ) {
148
+                return;
149
+            }
150
+
151
+            // If we're already on the page or the user doesn't have permissions, return.
152
+            if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) {
153
+                return;
154
+            }
155
+
156
+            // Finally redirect to the setup page.
157
+            wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) );
158
+
159
+            exit;
160
+        }
161
+
162
+    }
163
+
164
+    /**
165
+     * Generate an admin notice suggesting to start the wizard if there is no configuration.
166
+     *
167
+     * @since    3.9.0
168
+     */
169
+    public function admin_notices() {
170
+
171
+        // Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard.
172
+        if ( '' === $this->configuration_service->get_key() && ! $this->configuration_service->is_skip_wizard() ) { ?>
173 173
             <div id="wl-message" class="updated">
174 174
                 <p><?php esc_html_e( 'Welcome to WordLift &#8211; You&lsquo;re almost ready to start', 'wordlift' ); ?></p>
175 175
                 <p class="submit">
@@ -181,144 +181,144 @@  discard block
 block discarded – undo
181 181
             </div>
182 182
 		<?php }
183 183
 
184
-	}
185
-
186
-	/**
187
-	 * Handle hiding the wizard notices by user request.
188
-	 *
189
-	 * @since    3.9.0
190
-	 */
191
-	public function hide_notices() {
192
-
193
-		// If it's not a `wl-hide-notice` or the nonce is not set, return.
194
-		if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) {
195
-			return;
196
-		}
197
-
198
-		// If the nonce is invalid, return an error.
199
-		if ( ! wp_verify_nonce( $_GET['_wl_notice_nonce'], 'wordlift_hide_notices_nonce' ) ) {
200
-			wp_die( __( 'Action failed. Please refresh the page and retry.', 'wordlift' ) );
201
-		}
202
-
203
-		// If the user doesn't have the right privileges, return an error.
204
-		if ( ! current_user_can( 'manage_options' ) ) {
205
-			wp_die( __( 'Cheatin&#8217; huh?', 'wordlift' ) );
206
-		}
207
-
208
-		// Store a flag telling to skip the wizard.
209
-		$this->configuration_service->set_skip_wizard( true );
210
-
211
-	}
212
-
213
-	/**
214
-	 * Register the wizard page to be able to access it.
215
-	 *
216
-	 * @since    3.9.0
217
-	 */
218
-	public function admin_menu() {
219
-		/**
220
-		 * Filter: wl_feature__enable__screens.
221
-		 *
222
-		 * @param bool whether the screens needed to be registered, defaults to true.
223
-		 *
224
-		 * @return bool
225
-		 * @since 3.27.6
226
-		 */
227
-		if ( apply_filters( 'wl_feature__enable__screens', true ) ) {
228
-			// @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu.
229
-			add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' );
230
-		}
231
-	}
232
-
233
-	/**
234
-	 * Displays the wizard page.
235
-	 *
236
-	 * @since    3.9.0
237
-	 */
238
-	public function show_page() {
239
-
240
-		// First check if we are in the wizard page at all, if not do nothing.
241
-		if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) {
242
-			return;
243
-		}
244
-
245
-		// If it's a POST and the `wl-save-configuration` action is set, save the configuration.
246
-		if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) {
247
-
248
-			// Check the nonce and the user capabilities.
249
-			check_admin_referer( 'wl-save-configuration' );
250
-
251
-			// Check if the user has the right privileges.
252
-			if ( ! current_user_can( 'manage_options' ) ) {
253
-				wp_die( __( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) );
254
-			}
255
-
256
-			// Save the configuration.
257
-			$this->save_configuration( $_POST );
258
-
259
-			// Redirect to the admin's page.
260
-			wp_redirect( admin_url() );
261
-
262
-			exit;
263
-		}
264
-
265
-		$language_select = $this->language_select_element;
266
-		$country_select  = $this->country_select_element;
267
-
268
-		include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-setup.php';
269
-
270
-		exit;
271
-	}
272
-
273
-	/**
274
-	 * Save WordLift's configuration using the provided parameters.
275
-	 *
276
-	 * @param array $params An array of configuration parameters.
277
-	 *
278
-	 * @since 3.9.0
279
-	 *
280
-	 */
281
-	private function save_configuration( $params ) {
282
-
283
-		// We have the following parameters:
284
-		// `key`, holding WL's key,
285
-		// `vocabulary`, holding the vocabulary path,
286
-		// `language`, with the language code (e.g. `en`),
287
-		// `send_diagnostic`, the user preferences about sharing data with us.
288
-		// `user_type`, the user type either `personal` or `company`,
289
-		// `name`, with the `personal` or `company`'s name,
290
-		// `logo`, the attachment id for the `personal` or `company` entity.
291
-
292
-		// Store the key:
293
-		$this->configuration_service->set_key( $params['key'] );
294
-
295
-		// Store the vocabulary path:
296
-		$this->configuration_service->set_entity_base_path( $params['vocabulary'] );
297
-
298
-		// Store the site's language:
299
-		$this->configuration_service->set_language_code( $params['wl-site-language'] );
300
-
301
-		// Store the site's country:
302
-		$this->configuration_service->set_country_code( $params['wl-country-code'] );
303
-
304
-		// Store the preferences in variable, because if the checkbox is not checked
305
-		// the `share-diagnostic` will not exists in `$params` array.
306
-		$share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes';
307
-
308
-		// Store the diagnostic preferences:
309
-		$this->configuration_service->set_diagnostic_preferences( $share_diagnostic_preferences );
310
-
311
-		// Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
312
-		$type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' );
313
-
314
-		// Create an entity for the publisher.
315
-		$publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' );
316
-
317
-		// Store the publisher entity post id in the configuration.
318
-		$this->configuration_service->set_publisher_id( $publisher_post_id );
319
-
320
-		flush_rewrite_rules(); // Needed because of possible change to the entity base path.
321
-
322
-	}
184
+    }
185
+
186
+    /**
187
+     * Handle hiding the wizard notices by user request.
188
+     *
189
+     * @since    3.9.0
190
+     */
191
+    public function hide_notices() {
192
+
193
+        // If it's not a `wl-hide-notice` or the nonce is not set, return.
194
+        if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) {
195
+            return;
196
+        }
197
+
198
+        // If the nonce is invalid, return an error.
199
+        if ( ! wp_verify_nonce( $_GET['_wl_notice_nonce'], 'wordlift_hide_notices_nonce' ) ) {
200
+            wp_die( __( 'Action failed. Please refresh the page and retry.', 'wordlift' ) );
201
+        }
202
+
203
+        // If the user doesn't have the right privileges, return an error.
204
+        if ( ! current_user_can( 'manage_options' ) ) {
205
+            wp_die( __( 'Cheatin&#8217; huh?', 'wordlift' ) );
206
+        }
207
+
208
+        // Store a flag telling to skip the wizard.
209
+        $this->configuration_service->set_skip_wizard( true );
210
+
211
+    }
212
+
213
+    /**
214
+     * Register the wizard page to be able to access it.
215
+     *
216
+     * @since    3.9.0
217
+     */
218
+    public function admin_menu() {
219
+        /**
220
+         * Filter: wl_feature__enable__screens.
221
+         *
222
+         * @param bool whether the screens needed to be registered, defaults to true.
223
+         *
224
+         * @return bool
225
+         * @since 3.27.6
226
+         */
227
+        if ( apply_filters( 'wl_feature__enable__screens', true ) ) {
228
+            // @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu.
229
+            add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' );
230
+        }
231
+    }
232
+
233
+    /**
234
+     * Displays the wizard page.
235
+     *
236
+     * @since    3.9.0
237
+     */
238
+    public function show_page() {
239
+
240
+        // First check if we are in the wizard page at all, if not do nothing.
241
+        if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) {
242
+            return;
243
+        }
244
+
245
+        // If it's a POST and the `wl-save-configuration` action is set, save the configuration.
246
+        if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) {
247
+
248
+            // Check the nonce and the user capabilities.
249
+            check_admin_referer( 'wl-save-configuration' );
250
+
251
+            // Check if the user has the right privileges.
252
+            if ( ! current_user_can( 'manage_options' ) ) {
253
+                wp_die( __( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) );
254
+            }
255
+
256
+            // Save the configuration.
257
+            $this->save_configuration( $_POST );
258
+
259
+            // Redirect to the admin's page.
260
+            wp_redirect( admin_url() );
261
+
262
+            exit;
263
+        }
264
+
265
+        $language_select = $this->language_select_element;
266
+        $country_select  = $this->country_select_element;
267
+
268
+        include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-setup.php';
269
+
270
+        exit;
271
+    }
272
+
273
+    /**
274
+     * Save WordLift's configuration using the provided parameters.
275
+     *
276
+     * @param array $params An array of configuration parameters.
277
+     *
278
+     * @since 3.9.0
279
+     *
280
+     */
281
+    private function save_configuration( $params ) {
282
+
283
+        // We have the following parameters:
284
+        // `key`, holding WL's key,
285
+        // `vocabulary`, holding the vocabulary path,
286
+        // `language`, with the language code (e.g. `en`),
287
+        // `send_diagnostic`, the user preferences about sharing data with us.
288
+        // `user_type`, the user type either `personal` or `company`,
289
+        // `name`, with the `personal` or `company`'s name,
290
+        // `logo`, the attachment id for the `personal` or `company` entity.
291
+
292
+        // Store the key:
293
+        $this->configuration_service->set_key( $params['key'] );
294
+
295
+        // Store the vocabulary path:
296
+        $this->configuration_service->set_entity_base_path( $params['vocabulary'] );
297
+
298
+        // Store the site's language:
299
+        $this->configuration_service->set_language_code( $params['wl-site-language'] );
300
+
301
+        // Store the site's country:
302
+        $this->configuration_service->set_country_code( $params['wl-country-code'] );
303
+
304
+        // Store the preferences in variable, because if the checkbox is not checked
305
+        // the `share-diagnostic` will not exists in `$params` array.
306
+        $share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes';
307
+
308
+        // Store the diagnostic preferences:
309
+        $this->configuration_service->set_diagnostic_preferences( $share_diagnostic_preferences );
310
+
311
+        // Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
312
+        $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' );
313
+
314
+        // Create an entity for the publisher.
315
+        $publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' );
316
+
317
+        // Store the publisher entity post id in the configuration.
318
+        $this->configuration_service->set_publisher_id( $publisher_post_id );
319
+
320
+        flush_rewrite_rules(); // Needed because of possible change to the entity base path.
321
+
322
+    }
323 323
 
324 324
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @since      3.9.0
13 13
  */
14 14
 
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 * @since    3.9.0
86 86
 	 *
87 87
 	 */
88
-	public function __construct( $configuration_service, $key_validation_service, $entity_service, $language_select_element, $country_select_element ) {
88
+	public function __construct($configuration_service, $key_validation_service, $entity_service, $language_select_element, $country_select_element) {
89 89
 
90 90
 		// Set a reference to the configuration service.
91 91
 		$this->configuration_service = $configuration_service;
@@ -102,10 +102,10 @@  discard block
 block discarded – undo
102 102
 
103 103
 		// Hook to some WP's events:
104 104
 		// When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up.
105
-		add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
105
+		add_action('wp_loaded', array($this, 'hide_notices'));
106 106
 
107 107
 		// Hook to `admin_menu` in order to add our own setup wizard page.
108
-		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
108
+		add_action('admin_menu', array($this, 'admin_menu'));
109 109
 
110 110
 
111 111
 		/**
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 		 * @return bool
117 117
 		 * @since 3.27.6
118 118
 		 */
119
-		if ( apply_filters( 'wl_feature__enable__setup_screen', true ) ) {
119
+		if (apply_filters('wl_feature__enable__setup_screen', true)) {
120 120
 			// Triggered when the user accesses the admin area, we decide whether to show our own wizard.
121
-			add_action( 'admin_init', array( $this, 'show_page' ) );
121
+			add_action('admin_init', array($this, 'show_page'));
122 122
 		}
123 123
 		/**
124 124
 		 * Filter: wl_feature__enable__notices.
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 		 * @return bool
127 127
 		 * @since 3.27.6
128 128
 		 */
129
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
129
+		if (apply_filters('wl_feature__enable__notices', true)) {
130 130
 			// Hook to `admin_notices` to display our notices.
131
-			add_action( 'admin_notices', array( $this, 'admin_notices' ) );
131
+			add_action('admin_notices', array($this, 'admin_notices'));
132 132
 		}
133 133
 	}
134 134
 
@@ -140,21 +140,21 @@  discard block
 block discarded – undo
140 140
 	public function admin_init() {
141 141
 
142 142
 		// If the `_wl_activation_redirect` is set, the redirect to the setup page.
143
-		if ( get_transient( '_wl_activation_redirect' ) ) {
144
-			delete_transient( '_wl_activation_redirect' );
143
+		if (get_transient('_wl_activation_redirect')) {
144
+			delete_transient('_wl_activation_redirect');
145 145
 
146 146
 			// If the user asked to skip the wizard then comply.
147
-			if ( $this->configuration_service->is_skip_wizard() ) {
147
+			if ($this->configuration_service->is_skip_wizard()) {
148 148
 				return;
149 149
 			}
150 150
 
151 151
 			// If we're already on the page or the user doesn't have permissions, return.
152
-			if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) {
152
+			if (( ! empty($_GET['page']) && 'wl-setup' === $_GET['page']) || is_network_admin() || isset($_GET['activate-multi']) || ! current_user_can('manage_options')) {
153 153
 				return;
154 154
 			}
155 155
 
156 156
 			// Finally redirect to the setup page.
157
-			wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) );
157
+			wp_safe_redirect(admin_url('index.php?page=wl-setup'));
158 158
 
159 159
 			exit;
160 160
 		}
@@ -169,14 +169,14 @@  discard block
 block discarded – undo
169 169
 	public function admin_notices() {
170 170
 
171 171
 		// Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard.
172
-		if ( '' === $this->configuration_service->get_key() && ! $this->configuration_service->is_skip_wizard() ) { ?>
172
+		if ('' === $this->configuration_service->get_key() && ! $this->configuration_service->is_skip_wizard()) { ?>
173 173
             <div id="wl-message" class="updated">
174
-                <p><?php esc_html_e( 'Welcome to WordLift &#8211; You&lsquo;re almost ready to start', 'wordlift' ); ?></p>
174
+                <p><?php esc_html_e('Welcome to WordLift &#8211; You&lsquo;re almost ready to start', 'wordlift'); ?></p>
175 175
                 <p class="submit">
176
-                    <a href="<?php echo esc_url( admin_url( 'admin.php?page=wl-setup' ) ); ?>"
177
-                       class="button-primary"><?php esc_html_e( 'Run the Setup Wizard', 'wordlift' ); ?></a>
176
+                    <a href="<?php echo esc_url(admin_url('admin.php?page=wl-setup')); ?>"
177
+                       class="button-primary"><?php esc_html_e('Run the Setup Wizard', 'wordlift'); ?></a>
178 178
                     <a class="button-secondary skip"
179
-                       href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wl-hide-notice', 'install' ), 'wordlift_hide_notices_nonce', '_wl_notice_nonce' ) ); ?>"><?php esc_html_e( 'Skip Setup', 'wordlift' ); ?></a>
179
+                       href="<?php echo esc_url(wp_nonce_url(add_query_arg('wl-hide-notice', 'install'), 'wordlift_hide_notices_nonce', '_wl_notice_nonce')); ?>"><?php esc_html_e('Skip Setup', 'wordlift'); ?></a>
180 180
                 </p>
181 181
             </div>
182 182
 		<?php }
@@ -191,22 +191,22 @@  discard block
 block discarded – undo
191 191
 	public function hide_notices() {
192 192
 
193 193
 		// If it's not a `wl-hide-notice` or the nonce is not set, return.
194
-		if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) {
194
+		if ( ! isset($_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'])) {
195 195
 			return;
196 196
 		}
197 197
 
198 198
 		// If the nonce is invalid, return an error.
199
-		if ( ! wp_verify_nonce( $_GET['_wl_notice_nonce'], 'wordlift_hide_notices_nonce' ) ) {
200
-			wp_die( __( 'Action failed. Please refresh the page and retry.', 'wordlift' ) );
199
+		if ( ! wp_verify_nonce($_GET['_wl_notice_nonce'], 'wordlift_hide_notices_nonce')) {
200
+			wp_die(__('Action failed. Please refresh the page and retry.', 'wordlift'));
201 201
 		}
202 202
 
203 203
 		// If the user doesn't have the right privileges, return an error.
204
-		if ( ! current_user_can( 'manage_options' ) ) {
205
-			wp_die( __( 'Cheatin&#8217; huh?', 'wordlift' ) );
204
+		if ( ! current_user_can('manage_options')) {
205
+			wp_die(__('Cheatin&#8217; huh?', 'wordlift'));
206 206
 		}
207 207
 
208 208
 		// Store a flag telling to skip the wizard.
209
-		$this->configuration_service->set_skip_wizard( true );
209
+		$this->configuration_service->set_skip_wizard(true);
210 210
 
211 211
 	}
212 212
 
@@ -224,9 +224,9 @@  discard block
 block discarded – undo
224 224
 		 * @return bool
225 225
 		 * @since 3.27.6
226 226
 		 */
227
-		if ( apply_filters( 'wl_feature__enable__screens', true ) ) {
227
+		if (apply_filters('wl_feature__enable__screens', true)) {
228 228
 			// @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu.
229
-			add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' );
229
+			add_dashboard_page('', '', 'manage_options', 'wl-setup', '');
230 230
 		}
231 231
 	}
232 232
 
@@ -238,26 +238,26 @@  discard block
 block discarded – undo
238 238
 	public function show_page() {
239 239
 
240 240
 		// First check if we are in the wizard page at all, if not do nothing.
241
-		if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) {
241
+		if (empty($_GET['page']) || 'wl-setup' !== $_GET['page']) {
242 242
 			return;
243 243
 		}
244 244
 
245 245
 		// If it's a POST and the `wl-save-configuration` action is set, save the configuration.
246
-		if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) {
246
+		if (isset($_POST['action']) && 'wl-save-configuration' === $_POST['action']) {
247 247
 
248 248
 			// Check the nonce and the user capabilities.
249
-			check_admin_referer( 'wl-save-configuration' );
249
+			check_admin_referer('wl-save-configuration');
250 250
 
251 251
 			// Check if the user has the right privileges.
252
-			if ( ! current_user_can( 'manage_options' ) ) {
253
-				wp_die( __( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) );
252
+			if ( ! current_user_can('manage_options')) {
253
+				wp_die(__('Sorry, you do not have a permission to save the settings', 'wordlift'));
254 254
 			}
255 255
 
256 256
 			// Save the configuration.
257
-			$this->save_configuration( $_POST );
257
+			$this->save_configuration($_POST);
258 258
 
259 259
 			// Redirect to the admin's page.
260
-			wp_redirect( admin_url() );
260
+			wp_redirect(admin_url());
261 261
 
262 262
 			exit;
263 263
 		}
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 		$language_select = $this->language_select_element;
266 266
 		$country_select  = $this->country_select_element;
267 267
 
268
-		include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-setup.php';
268
+		include plugin_dir_path(dirname(__FILE__)).'admin/partials/wordlift-admin-setup.php';
269 269
 
270 270
 		exit;
271 271
 	}
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 	 * @since 3.9.0
279 279
 	 *
280 280
 	 */
281
-	private function save_configuration( $params ) {
281
+	private function save_configuration($params) {
282 282
 
283 283
 		// We have the following parameters:
284 284
 		// `key`, holding WL's key,
@@ -290,32 +290,32 @@  discard block
 block discarded – undo
290 290
 		// `logo`, the attachment id for the `personal` or `company` entity.
291 291
 
292 292
 		// Store the key:
293
-		$this->configuration_service->set_key( $params['key'] );
293
+		$this->configuration_service->set_key($params['key']);
294 294
 
295 295
 		// Store the vocabulary path:
296
-		$this->configuration_service->set_entity_base_path( $params['vocabulary'] );
296
+		$this->configuration_service->set_entity_base_path($params['vocabulary']);
297 297
 
298 298
 		// Store the site's language:
299
-		$this->configuration_service->set_language_code( $params['wl-site-language'] );
299
+		$this->configuration_service->set_language_code($params['wl-site-language']);
300 300
 
301 301
 		// Store the site's country:
302
-		$this->configuration_service->set_country_code( $params['wl-country-code'] );
302
+		$this->configuration_service->set_country_code($params['wl-country-code']);
303 303
 
304 304
 		// Store the preferences in variable, because if the checkbox is not checked
305 305
 		// the `share-diagnostic` will not exists in `$params` array.
306
-		$share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes';
306
+		$share_diagnostic_preferences = empty($params['share-diagnostic']) ? 'no' : 'yes';
307 307
 
308 308
 		// Store the diagnostic preferences:
309
-		$this->configuration_service->set_diagnostic_preferences( $share_diagnostic_preferences );
309
+		$this->configuration_service->set_diagnostic_preferences($share_diagnostic_preferences);
310 310
 
311 311
 		// Set the type URI, either http://schema.org/Person or http://schema.org/Organization.
312
-		$type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' );
312
+		$type_uri = sprintf('http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person');
313 313
 
314 314
 		// Create an entity for the publisher.
315
-		$publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' );
315
+		$publisher_post_id = $this->entity_service->create($params['name'], $type_uri, $params['logo'], 'publish');
316 316
 
317 317
 		// Store the publisher entity post id in the configuration.
318
-		$this->configuration_service->set_publisher_id( $publisher_post_id );
318
+		$this->configuration_service->set_publisher_id($publisher_post_id);
319 319
 
320 320
 		flush_rewrite_rules(); // Needed because of possible change to the entity base path.
321 321
 
Please login to merge, or discard this patch.