Completed
Push — master ( 48986a...95c69f )
by David
06:07
created
src/public/class-wordlift-seo-service.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -21,66 +21,66 @@
 block discarded – undo
21 21
  */
22 22
 class Wordlift_Seo_Service {
23 23
 
24
-	/**
25
-	 * @inheritdoc
26
-	 */
27
-	function __construct() {
24
+    /**
25
+     * @inheritdoc
26
+     */
27
+    function __construct() {
28 28
 
29
-		// If we are not on the admin, run the get_term filter for entity type terms.
30
-		add_filter( 'get_wl_entity_type', array(
31
-			$this,
32
-			'get_wl_entity_type',
33
-		), 10, 2 );
29
+        // If we are not on the admin, run the get_term filter for entity type terms.
30
+        add_filter( 'get_wl_entity_type', array(
31
+            $this,
32
+            'get_wl_entity_type',
33
+        ), 10, 2 );
34 34
 
35
-	}
35
+    }
36 36
 
37
-	/**
38
-	 * Filter the entity term object, and when not in admin context replace title
39
-	 * and description with whatever was set in the entity settings page.
40
-	 *
41
-	 * @since    3.11
42
-	 *
43
-	 * @param WP_Term $term     The term to filters.
44
-	 * @param string  $taxonomy The taxonomy name.
45
-	 *
46
-	 * @return WP_Term The {@link WP_Term} with fields changed.
47
-	 */
48
-	function get_wl_entity_type( $term, $taxonomy ) {
37
+    /**
38
+     * Filter the entity term object, and when not in admin context replace title
39
+     * and description with whatever was set in the entity settings page.
40
+     *
41
+     * @since    3.11
42
+     *
43
+     * @param WP_Term $term     The term to filters.
44
+     * @param string  $taxonomy The taxonomy name.
45
+     *
46
+     * @return WP_Term The {@link WP_Term} with fields changed.
47
+     */
48
+    function get_wl_entity_type( $term, $taxonomy ) {
49 49
 
50
-		// Do nothing when in admin.
51
-		if ( is_admin() ) {
52
-			return $term;
53
-		}
50
+        // Do nothing when in admin.
51
+        if ( is_admin() ) {
52
+            return $term;
53
+        }
54 54
 
55
-		// Get the terms' settings.
56
-		$entity_settings = get_option( 'wl_entity_type_settings', array() );
55
+        // Get the terms' settings.
56
+        $entity_settings = get_option( 'wl_entity_type_settings', array() );
57 57
 
58
-		// If we have no settings for the specified term, then return the original
59
-		// term.
60
-		if ( ! isset( $entity_settings[ $term->term_id ] ) ) {
58
+        // If we have no settings for the specified term, then return the original
59
+        // term.
60
+        if ( ! isset( $entity_settings[ $term->term_id ] ) ) {
61 61
 
62
-			return $term;
63
-		}
62
+            return $term;
63
+        }
64 64
 
65
-		// Get the settings for the specified term.
66
-		$settings = $entity_settings[ $term->term_id ];
65
+        // Get the settings for the specified term.
66
+        $settings = $entity_settings[ $term->term_id ];
67 67
 
68
-		// Update the name.
69
-		if ( ! empty( $settings['title'] ) ) {
68
+        // Update the name.
69
+        if ( ! empty( $settings['title'] ) ) {
70 70
 
71
-			$term->name = $settings['title'];
71
+            $term->name = $settings['title'];
72 72
 
73
-		}
73
+        }
74 74
 
75
-		// Update the description.
76
-		if ( ! empty( $settings['description'] ) ) {
75
+        // Update the description.
76
+        if ( ! empty( $settings['description'] ) ) {
77 77
 
78
-			$term->description = $settings['description'];
78
+            $term->description = $settings['description'];
79 79
 
80
-		}
80
+        }
81 81
 
82
-		// Return the updated term.
83
-		return $term;
84
-	}
82
+        // Return the updated term.
83
+        return $term;
84
+    }
85 85
 
86 86
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -27,10 +27,10 @@  discard block
 block discarded – undo
27 27
 	function __construct() {
28 28
 
29 29
 		// If we are not on the admin, run the get_term filter for entity type terms.
30
-		add_filter( 'get_wl_entity_type', array(
30
+		add_filter('get_wl_entity_type', array(
31 31
 			$this,
32 32
 			'get_wl_entity_type',
33
-		), 10, 2 );
33
+		), 10, 2);
34 34
 
35 35
 	}
36 36
 
@@ -45,35 +45,35 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @return WP_Term The {@link WP_Term} with fields changed.
47 47
 	 */
48
-	function get_wl_entity_type( $term, $taxonomy ) {
48
+	function get_wl_entity_type($term, $taxonomy) {
49 49
 
50 50
 		// Do nothing when in admin.
51
-		if ( is_admin() ) {
51
+		if (is_admin()) {
52 52
 			return $term;
53 53
 		}
54 54
 
55 55
 		// Get the terms' settings.
56
-		$entity_settings = get_option( 'wl_entity_type_settings', array() );
56
+		$entity_settings = get_option('wl_entity_type_settings', array());
57 57
 
58 58
 		// If we have no settings for the specified term, then return the original
59 59
 		// term.
60
-		if ( ! isset( $entity_settings[ $term->term_id ] ) ) {
60
+		if ( ! isset($entity_settings[$term->term_id])) {
61 61
 
62 62
 			return $term;
63 63
 		}
64 64
 
65 65
 		// Get the settings for the specified term.
66
-		$settings = $entity_settings[ $term->term_id ];
66
+		$settings = $entity_settings[$term->term_id];
67 67
 
68 68
 		// Update the name.
69
-		if ( ! empty( $settings['title'] ) ) {
69
+		if ( ! empty($settings['title'])) {
70 70
 
71 71
 			$term->name = $settings['title'];
72 72
 
73 73
 		}
74 74
 
75 75
 		// Update the description.
76
-		if ( ! empty( $settings['description'] ) ) {
76
+		if ( ! empty($settings['description'])) {
77 77
 
78 78
 			$term->description = $settings['description'];
79 79
 
Please login to merge, or discard this patch.
src/public/class-wordlift-widget.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -16,26 +16,26 @@
 block discarded – undo
16 16
  */
17 17
 abstract class Wordlift_Widget extends WP_Widget {
18 18
 
19
-	/**
20
-	 * @inheritdoc
21
-	 */
22
-	public function __construct( $id_base, $name, array $widget_options = array(), array $control_options = array() ) {
23
-		parent::__construct( $id_base, $name, $widget_options, $control_options );
19
+    /**
20
+     * @inheritdoc
21
+     */
22
+    public function __construct( $id_base, $name, array $widget_options = array(), array $control_options = array() ) {
23
+        parent::__construct( $id_base, $name, $widget_options, $control_options );
24 24
 
25
-		// Initialize the Related Entities Cloud Widget.
26
-		add_action( 'widgets_init', array( $this, 'widget_init' ) );
25
+        // Initialize the Related Entities Cloud Widget.
26
+        add_action( 'widgets_init', array( $this, 'widget_init' ) );
27 27
 
28
-	}
28
+    }
29 29
 
30
-	/**
31
-	 * Register the related entities cloud widget
32
-	 *
33
-	 * @since 3.11.0
34
-	 */
35
-	public function widget_init() {
30
+    /**
31
+     * Register the related entities cloud widget
32
+     *
33
+     * @since 3.11.0
34
+     */
35
+    public function widget_init() {
36 36
 
37
-		register_widget( get_class( $this ) );
37
+        register_widget( get_class( $this ) );
38 38
 
39
-	}
39
+    }
40 40
 
41 41
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@  discard block
 block discarded – undo
19 19
 	/**
20 20
 	 * @inheritdoc
21 21
 	 */
22
-	public function __construct( $id_base, $name, array $widget_options = array(), array $control_options = array() ) {
23
-		parent::__construct( $id_base, $name, $widget_options, $control_options );
22
+	public function __construct($id_base, $name, array $widget_options = array(), array $control_options = array()) {
23
+		parent::__construct($id_base, $name, $widget_options, $control_options);
24 24
 
25 25
 		// Initialize the Related Entities Cloud Widget.
26
-		add_action( 'widgets_init', array( $this, 'widget_init' ) );
26
+		add_action('widgets_init', array($this, 'widget_init'));
27 27
 
28 28
 	}
29 29
 
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 */
35 35
 	public function widget_init() {
36 36
 
37
-		register_widget( get_class( $this ) );
37
+		register_widget(get_class($this));
38 38
 
39 39
 	}
40 40
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-log-service.php 2 patches
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -7,111 +7,111 @@
 block discarded – undo
7 7
  */
8 8
 class Wordlift_Log_Service {
9 9
 
10
-	const MESSAGE_TEMPLATE = '%-6s [%-40.40s] %s';
10
+    const MESSAGE_TEMPLATE = '%-6s [%-40.40s] %s';
11 11
 
12
-	const ERROR = 'ERROR';
13
-	const WARN = 'WARN';
14
-	const INFO = 'INFO';
15
-	const DEBUG = 'DEBUG';
16
-	const TRACE = 'TRACE';
12
+    const ERROR = 'ERROR';
13
+    const WARN = 'WARN';
14
+    const INFO = 'INFO';
15
+    const DEBUG = 'DEBUG';
16
+    const TRACE = 'TRACE';
17 17
 
18 18
 
19
-	/**
20
-	 * The class related to the logs.
21
-	 *
22
-	 * @since  1.0.0
23
-	 * @access private
24
-	 * @var string $class_name The class related to the logs.
25
-	 */
26
-	private $class_name;
19
+    /**
20
+     * The class related to the logs.
21
+     *
22
+     * @since  1.0.0
23
+     * @access private
24
+     * @var string $class_name The class related to the logs.
25
+     */
26
+    private $class_name;
27 27
 
28
-	/**
29
-	 * A singleton instance for legacy logging.
30
-	 *
31
-	 * @since  3.10.0
32
-	 * @access private
33
-	 * @var \Wordlift_Log_Service $instance A singleton instance for legacy logging.
34
-	 */
35
-	private static $instance = null;
28
+    /**
29
+     * A singleton instance for legacy logging.
30
+     *
31
+     * @since  3.10.0
32
+     * @access private
33
+     * @var \Wordlift_Log_Service $instance A singleton instance for legacy logging.
34
+     */
35
+    private static $instance = null;
36 36
 
37
-	/**
38
-	 * Create an instance of the Log service.
39
-	 * @since 1.0.0
40
-	 *
41
-	 * @param string $class_name The class related to the logs.
42
-	 */
43
-	public function __construct( $class_name ) {
37
+    /**
38
+     * Create an instance of the Log service.
39
+     * @since 1.0.0
40
+     *
41
+     * @param string $class_name The class related to the logs.
42
+     */
43
+    public function __construct( $class_name ) {
44 44
 
45
-		$this->class_name = $class_name;
45
+        $this->class_name = $class_name;
46 46
 
47
-	}
47
+    }
48 48
 
49
-	/**
50
-	 * Get the ROOT logger.
51
-	 *
52
-	 * @since 3.10.0
53
-	 *
54
-	 * @return \Wordlift_Log_Service A singleton instance for legacy logging.
55
-	 */
56
-	public static function get_instance() {
49
+    /**
50
+     * Get the ROOT logger.
51
+     *
52
+     * @since 3.10.0
53
+     *
54
+     * @return \Wordlift_Log_Service A singleton instance for legacy logging.
55
+     */
56
+    public static function get_instance() {
57 57
 
58
-		return self::$instance ?: self::$instance = new Wordlift_Log_Service( 'ROOT' );
59
-	}
58
+        return self::$instance ?: self::$instance = new Wordlift_Log_Service( 'ROOT' );
59
+    }
60 60
 
61 61
 
62
-	public static function get_logger( $class_name ) {
62
+    public static function get_logger( $class_name ) {
63 63
 
64
-		return new Wordlift_Log_Service( $class_name );
64
+        return new Wordlift_Log_Service( $class_name );
65 65
 
66
-	}
66
+    }
67 67
 
68
-	/**
69
-	 * Log a message.
70
-	 *
71
-	 * @since 1.0.0
72
-	 *
73
-	 * @param string $level   The log level.
74
-	 * @param string $message The message to log.
75
-	 */
76
-	public function log( $level, $message ) {
68
+    /**
69
+     * Log a message.
70
+     *
71
+     * @since 1.0.0
72
+     *
73
+     * @param string $level   The log level.
74
+     * @param string $message The message to log.
75
+     */
76
+    public function log( $level, $message ) {
77 77
 
78
-		// If we're tracing or debugging, but the debug flag isn't set, then we don't log.
79
-		if ( ( self::TRACE === $level || self::DEBUG === $level ) && ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) ) {
80
-			return;
81
-		}
78
+        // If we're tracing or debugging, but the debug flag isn't set, then we don't log.
79
+        if ( ( self::TRACE === $level || self::DEBUG === $level ) && ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) ) {
80
+            return;
81
+        }
82 82
 
83
-		error_log( sprintf( self::MESSAGE_TEMPLATE, $level, $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) );
83
+        error_log( sprintf( self::MESSAGE_TEMPLATE, $level, $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) );
84 84
 
85
-	}
85
+    }
86 86
 
87
-	public function error( $message ) {
87
+    public function error( $message ) {
88 88
 
89
-		$this->log( self::ERROR, $message );
89
+        $this->log( self::ERROR, $message );
90 90
 
91
-	}
91
+    }
92 92
 
93
-	public function warn( $message ) {
93
+    public function warn( $message ) {
94 94
 
95
-		$this->log( self::WARN, $message );
95
+        $this->log( self::WARN, $message );
96 96
 
97
-	}
97
+    }
98 98
 
99
-	public function info( $message ) {
99
+    public function info( $message ) {
100 100
 
101
-		$this->log( self::INFO, $message );
101
+        $this->log( self::INFO, $message );
102 102
 
103
-	}
103
+    }
104 104
 
105
-	public function debug( $message ) {
105
+    public function debug( $message ) {
106 106
 
107
-		$this->log( self::DEBUG, $message );
107
+        $this->log( self::DEBUG, $message );
108 108
 
109
-	}
109
+    }
110 110
 
111
-	public function trace( $message ) {
111
+    public function trace( $message ) {
112 112
 
113
-		$this->log( self::TRACE, $message );
113
+        $this->log( self::TRACE, $message );
114 114
 
115
-	}
115
+    }
116 116
 
117 117
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 *
41 41
 	 * @param string $class_name The class related to the logs.
42 42
 	 */
43
-	public function __construct( $class_name ) {
43
+	public function __construct($class_name) {
44 44
 
45 45
 		$this->class_name = $class_name;
46 46
 
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 55
 	 */
56 56
 	public static function get_instance() {
57 57
 
58
-		return self::$instance ?: self::$instance = new Wordlift_Log_Service( 'ROOT' );
58
+		return self::$instance ?: self::$instance = new Wordlift_Log_Service('ROOT');
59 59
 	}
60 60
 
61 61
 
62
-	public static function get_logger( $class_name ) {
62
+	public static function get_logger($class_name) {
63 63
 
64
-		return new Wordlift_Log_Service( $class_name );
64
+		return new Wordlift_Log_Service($class_name);
65 65
 
66 66
 	}
67 67
 
@@ -73,44 +73,44 @@  discard block
 block discarded – undo
73 73
 	 * @param string $level   The log level.
74 74
 	 * @param string $message The message to log.
75 75
 	 */
76
-	public function log( $level, $message ) {
76
+	public function log($level, $message) {
77 77
 
78 78
 		// If we're tracing or debugging, but the debug flag isn't set, then we don't log.
79
-		if ( ( self::TRACE === $level || self::DEBUG === $level ) && ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) ) {
79
+		if ((self::TRACE === $level || self::DEBUG === $level) && ( ! defined('WP_DEBUG') || ! WP_DEBUG)) {
80 80
 			return;
81 81
 		}
82 82
 
83
-		error_log( sprintf( self::MESSAGE_TEMPLATE, $level, $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) );
83
+		error_log(sprintf(self::MESSAGE_TEMPLATE, $level, $this->class_name, is_array($message) ? implode(', ', $message) : $message));
84 84
 
85 85
 	}
86 86
 
87
-	public function error( $message ) {
87
+	public function error($message) {
88 88
 
89
-		$this->log( self::ERROR, $message );
89
+		$this->log(self::ERROR, $message);
90 90
 
91 91
 	}
92 92
 
93
-	public function warn( $message ) {
93
+	public function warn($message) {
94 94
 
95
-		$this->log( self::WARN, $message );
95
+		$this->log(self::WARN, $message);
96 96
 
97 97
 	}
98 98
 
99
-	public function info( $message ) {
99
+	public function info($message) {
100 100
 
101
-		$this->log( self::INFO, $message );
101
+		$this->log(self::INFO, $message);
102 102
 
103 103
 	}
104 104
 
105
-	public function debug( $message ) {
105
+	public function debug($message) {
106 106
 
107
-		$this->log( self::DEBUG, $message );
107
+		$this->log(self::DEBUG, $message);
108 108
 
109 109
 	}
110 110
 
111
-	public function trace( $message ) {
111
+	public function trace($message) {
112 112
 
113
-		$this->log( self::TRACE, $message );
113
+		$this->log(self::TRACE, $message);
114 114
 
115 115
 	}
116 116
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-key-validation-service.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -17,42 +17,42 @@
 block discarded – undo
17 17
  */
18 18
 class Wordlift_Key_Validation_Service {
19 19
 
20
-	/**
21
-	 * Validate the provided key.
22
-	 *
23
-	 * @since 3.9.0
24
-	 *
25
-	 * @param string $key WordLift's key to validate.
26
-	 *
27
-	 * @return bool True if the key is valid, otherwise false.
28
-	 */
29
-	public function is_valid( $key ) {
30
-
31
-		// Request the dataset URI as a way to validate the key
32
-		$response = wp_remote_get( wl_configuration_get_accounts_by_key_dataset_uri( $key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) );
33
-
34
-		// If the response is valid, the key is valid.
35
-		return ! is_wp_error( $response ) && 200 === (int) $response['response']['code'];
36
-	}
37
-
38
-	/**
39
-	 * This function is hooked to the `wl_validate_key` AJAX call.
40
-	 *
41
-	 * @since 3.9.0
42
-	 */
43
-	public function validate_key() {
44
-
45
-		// Ensure we don't have garbage before us.
46
-		ob_clean();
47
-
48
-		// Check if we have a key.
49
-		if ( ! isset( $_POST['key'] ) ) {
50
-			wp_send_json_error( 'The key parameter is required.' );
51
-		}
52
-
53
-		// Set a response with valid set to true or false according to the key validity.
54
-		wp_send_json_success( array( 'valid' => $this->is_valid( $_POST['key'] ) ) );
55
-
56
-	}
20
+    /**
21
+     * Validate the provided key.
22
+     *
23
+     * @since 3.9.0
24
+     *
25
+     * @param string $key WordLift's key to validate.
26
+     *
27
+     * @return bool True if the key is valid, otherwise false.
28
+     */
29
+    public function is_valid( $key ) {
30
+
31
+        // Request the dataset URI as a way to validate the key
32
+        $response = wp_remote_get( wl_configuration_get_accounts_by_key_dataset_uri( $key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) );
33
+
34
+        // If the response is valid, the key is valid.
35
+        return ! is_wp_error( $response ) && 200 === (int) $response['response']['code'];
36
+    }
37
+
38
+    /**
39
+     * This function is hooked to the `wl_validate_key` AJAX call.
40
+     *
41
+     * @since 3.9.0
42
+     */
43
+    public function validate_key() {
44
+
45
+        // Ensure we don't have garbage before us.
46
+        ob_clean();
47
+
48
+        // Check if we have a key.
49
+        if ( ! isset( $_POST['key'] ) ) {
50
+            wp_send_json_error( 'The key parameter is required.' );
51
+        }
52
+
53
+        // Set a response with valid set to true or false according to the key validity.
54
+        wp_send_json_success( array( 'valid' => $this->is_valid( $_POST['key'] ) ) );
55
+
56
+    }
57 57
 
58 58
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -26,13 +26,13 @@  discard block
 block discarded – undo
26 26
 	 *
27 27
 	 * @return bool True if the key is valid, otherwise false.
28 28
 	 */
29
-	public function is_valid( $key ) {
29
+	public function is_valid($key) {
30 30
 
31 31
 		// Request the dataset URI as a way to validate the key
32
-		$response = wp_remote_get( wl_configuration_get_accounts_by_key_dataset_uri( $key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) );
32
+		$response = wp_remote_get(wl_configuration_get_accounts_by_key_dataset_uri($key), unserialize(WL_REDLINK_API_HTTP_OPTIONS));
33 33
 
34 34
 		// If the response is valid, the key is valid.
35
-		return ! is_wp_error( $response ) && 200 === (int) $response['response']['code'];
35
+		return ! is_wp_error($response) && 200 === (int) $response['response']['code'];
36 36
 	}
37 37
 
38 38
 	/**
@@ -46,12 +46,12 @@  discard block
 block discarded – undo
46 46
 		ob_clean();
47 47
 
48 48
 		// Check if we have a key.
49
-		if ( ! isset( $_POST['key'] ) ) {
50
-			wp_send_json_error( 'The key parameter is required.' );
49
+		if ( ! isset($_POST['key'])) {
50
+			wp_send_json_error('The key parameter is required.');
51 51
 		}
52 52
 
53 53
 		// Set a response with valid set to true or false according to the key validity.
54
-		wp_send_json_success( array( 'valid' => $this->is_valid( $_POST['key'] ) ) );
54
+		wp_send_json_success(array('valid' => $this->is_valid($_POST['key'])));
55 55
 
56 56
 	}
57 57
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-publisher-ajax-adapter.php 2 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -16,55 +16,55 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Publisher_Ajax_Adapter {
18 18
 
19
-	/**
20
-	 * The {@link Wordlift_Publisher_Service} instance.
21
-	 *
22
-	 * @since  3.11.0
23
-	 * @access private
24
-	 * @var Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
25
-	 */
26
-	private $publisher_service;
19
+    /**
20
+     * The {@link Wordlift_Publisher_Service} instance.
21
+     *
22
+     * @since  3.11.0
23
+     * @access private
24
+     * @var Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
25
+     */
26
+    private $publisher_service;
27 27
 
28
-	/**
29
-	 * Create a {@link Wordlift_Publisher_Ajax_Adapter} instance.
30
-	 *
31
-	 * @since 3.11.0
32
-	 *
33
-	 * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
34
-	 */
35
-	function __construct( $publisher_service ) {
28
+    /**
29
+     * Create a {@link Wordlift_Publisher_Ajax_Adapter} instance.
30
+     *
31
+     * @since 3.11.0
32
+     *
33
+     * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
34
+     */
35
+    function __construct( $publisher_service ) {
36 36
 
37
-		$this->publisher_service = $publisher_service;
37
+        $this->publisher_service = $publisher_service;
38 38
 
39
-	}
39
+    }
40 40
 
41
-	/**
42
-	 * The publisher AJAX action. This function is hook to the `wl_publisher`
43
-	 * action.
44
-	 *
45
-	 * @since 3.11.0
46
-	 */
47
-	public function publisher() {
41
+    /**
42
+     * The publisher AJAX action. This function is hook to the `wl_publisher`
43
+     * action.
44
+     *
45
+     * @since 3.11.0
46
+     */
47
+    public function publisher() {
48 48
 
49
-		// Ensure we don't have garbage before us.
50
-		ob_clean();
49
+        // Ensure we don't have garbage before us.
50
+        ob_clean();
51 51
 
52
-		// Check if the current user can `manage_options`.
53
-		if ( ! current_user_can( 'manage_options' ) ) {
54
-			wp_send_json_error( 'Access denied.' );
55
-		}
52
+        // Check if the current user can `manage_options`.
53
+        if ( ! current_user_can( 'manage_options' ) ) {
54
+            wp_send_json_error( 'Access denied.' );
55
+        }
56 56
 
57
-		// No actual search parameter was passed, bail out.
58
-		if ( ! isset( $_POST['q'] ) || empty( $_POST['q'] ) ) {
59
-			wp_send_json_error( 'The q parameter is required.' );
60
-		}
57
+        // No actual search parameter was passed, bail out.
58
+        if ( ! isset( $_POST['q'] ) || empty( $_POST['q'] ) ) {
59
+            wp_send_json_error( 'The q parameter is required.' );
60
+        }
61 61
 
62
-		// Get the response.
63
-		$response = $this->publisher_service->query( $_POST['q'] );
62
+        // Get the response.
63
+        $response = $this->publisher_service->query( $_POST['q'] );
64 64
 
65
-		// Finally output the response.
66
-		wp_send_json_success( $response );
65
+        // Finally output the response.
66
+        wp_send_json_success( $response );
67 67
 
68
-	}
68
+    }
69 69
 
70 70
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
34 34
 	 */
35
-	function __construct( $publisher_service ) {
35
+	function __construct($publisher_service) {
36 36
 
37 37
 		$this->publisher_service = $publisher_service;
38 38
 
@@ -50,20 +50,20 @@  discard block
 block discarded – undo
50 50
 		ob_clean();
51 51
 
52 52
 		// Check if the current user can `manage_options`.
53
-		if ( ! current_user_can( 'manage_options' ) ) {
54
-			wp_send_json_error( 'Access denied.' );
53
+		if ( ! current_user_can('manage_options')) {
54
+			wp_send_json_error('Access denied.');
55 55
 		}
56 56
 
57 57
 		// No actual search parameter was passed, bail out.
58
-		if ( ! isset( $_POST['q'] ) || empty( $_POST['q'] ) ) {
59
-			wp_send_json_error( 'The q parameter is required.' );
58
+		if ( ! isset($_POST['q']) || empty($_POST['q'])) {
59
+			wp_send_json_error('The q parameter is required.');
60 60
 		}
61 61
 
62 62
 		// Get the response.
63
-		$response = $this->publisher_service->query( $_POST['q'] );
63
+		$response = $this->publisher_service->query($_POST['q']);
64 64
 
65 65
 		// Finally output the response.
66
-		wp_send_json_success( $response );
66
+		wp_send_json_success($response);
67 67
 
68 68
 	}
69 69
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-entity-post-type-service.php 2 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -16,152 +16,152 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Entity_Post_Type_Service {
18 18
 
19
-	/**
20
-	 * The entity post type.
21
-	 *
22
-	 * @since  3.6.0
23
-	 * @access private
24
-	 * @var string $post_type The entity post type.
25
-	 */
26
-	private $post_type;
27
-
28
-	/**
29
-	 * The entity type slug.
30
-	 *
31
-	 * @since  3.6.0
32
-	 * @access private
33
-	 * @var string $slug The entity type slug.
34
-	 */
35
-	private $slug;
36
-
37
-	/**
38
-	 * A singleton instance of the entity type service.
39
-	 *
40
-	 * @since  3.6.0
41
-	 * @access private
42
-	 * @var Wordlift_Entity_Post_Type_Service
43
-	 */
44
-	private static $instance;
45
-
46
-	/**
47
-	 * Create an entity type service instance.
48
-	 *
49
-	 * @since 3.6.0
50
-	 *
51
-	 * @param string $post_type The post type, e.g. entity.
52
-	 * @param string $slug      The entity type slug, if the slug is empty, the default slug will be used.
53
-	 */
54
-	public function __construct( $post_type, $slug ) {
55
-
56
-
57
-		$this->post_type = $post_type;
58
-
59
-		// We cannot assign an empty slug to the register_post_type function, therefore if the slug is empty we default
60
-		// to the type name.
61
-		$this->slug = $slug ?: $post_type;
62
-
63
-		self::$instance = $this;
64
-
65
-	}
66
-
67
-	/**
68
-	 * Get the entity type service singleton instance.
69
-	 *
70
-	 * @since 3.6.0
71
-	 *
72
-	 * @return Wordlift_Entity_Post_Type_Service The entity type service singleton instance.
73
-	 */
74
-	public static function get_instance() {
75
-
76
-		return self::$instance;
77
-	}
78
-
79
-	/**
80
-	 * Get the entity type slug.
81
-	 *
82
-	 * @since 3.6.0
83
-	 *
84
-	 * @return string The entity type slug.
85
-	 */
86
-	public function get_slug() {
87
-
88
-		return $this->slug;
89
-	}
90
-
91
-	/**
92
-	 * Get the entity post type name.
93
-	 *
94
-	 * @since 3.6.0
95
-	 *
96
-	 * @return string The entity post type.
97
-	 */
98
-	public function get_post_type() {
99
-
100
-		return $this->post_type;
101
-	}
102
-
103
-
104
-	/**
105
-	 * Register the WordLift entity post type. This method is hooked to WordPress' init action.
106
-	 *
107
-	 * @since 3.6.0
108
-	 */
109
-	public function register() {
110
-
111
-		$labels = array(
112
-			'name'               => _x( 'Vocabulary', 'post type general name', 'wordlift' ),
113
-			'singular_name'      => _x( 'Entity', 'post type singular name', 'wordlift' ),
114
-			'add_new'            => _x( 'Add New Entity', 'entity', 'wordlift' ),
115
-			'add_new_item'       => __( 'Add New Entity', 'wordlift' ),
116
-			'edit_item'          => __( 'Edit Entity', 'wordlift' ),
117
-			'new_item'           => __( 'New Entity', 'wordlift' ),
118
-			'all_items'          => __( 'All Entities', 'wordlift' ),
119
-			'view_item'          => __( 'View Entity', 'wordlift' ),
120
-			'search_items'       => __( 'Search in Vocabulary', 'wordlift' ),
121
-			'not_found'          => __( 'No entities found', 'wordlift' ),
122
-			'not_found_in_trash' => __( 'No entities found in the Trash', 'wordlift' ),
123
-			'parent_item_colon'  => '',
124
-			'menu_name'          => __( 'Vocabulary', 'wordlift' ),
125
-		);
126
-
127
-		$args = array(
128
-			'labels'        => $labels,
129
-			'description'   => 'Holds our vocabulary (set of entities) and entity specific data',
130
-			'public'        => true,
131
-			'menu_position' => 20,
132
-			// after the pages menu.
133
-			// Add support for 'authors' and 'revisions':
134
-			// * see https://github.com/insideout10/wordlift-plugin/issues/395
135
-			// * see https://github.com/insideout10/wordlift-plugin/issues/376
136
-			'supports'      => array(
137
-				'title',
138
-				'editor',
139
-				'thumbnail',
140
-				'excerpt',
141
-				'comments',
142
-				'author',
143
-				// Disabling revisions support.
144
-				//
145
-				// See https://github.com/insideout10/wordlift-plugin/issues/462
146
-				// 'revisions',
147
-			),
148
-			'has_archive'   => true,
149
-			'menu_icon'     => WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-vocabulary-icon.svg',
150
-			// Although we define our slug here, we further manage linking to entities using the Wordlift_Entity_Link_Service.
151
-			'rewrite'       => array( 'slug' => $this->slug ),
152
-		);
153
-
154
-		register_post_type( $this->post_type, $args );
155
-
156
-		// Enable WP's standard `category` taxonomy for entities.
157
-		//
158
-		// While this enables editors to bind entities to the WP posts' category
159
-		// taxonomy, in Wordlift_Category_Taxonomy_Service we also need to alter
160
-		// WP's main category query to include the `entity` post type.
161
-		//
162
-		// See https://github.com/insideout10/wordlift-plugin/issues/442
163
-		register_taxonomy_for_object_type( 'category', $this->post_type );
164
-
165
-	}
19
+    /**
20
+     * The entity post type.
21
+     *
22
+     * @since  3.6.0
23
+     * @access private
24
+     * @var string $post_type The entity post type.
25
+     */
26
+    private $post_type;
27
+
28
+    /**
29
+     * The entity type slug.
30
+     *
31
+     * @since  3.6.0
32
+     * @access private
33
+     * @var string $slug The entity type slug.
34
+     */
35
+    private $slug;
36
+
37
+    /**
38
+     * A singleton instance of the entity type service.
39
+     *
40
+     * @since  3.6.0
41
+     * @access private
42
+     * @var Wordlift_Entity_Post_Type_Service
43
+     */
44
+    private static $instance;
45
+
46
+    /**
47
+     * Create an entity type service instance.
48
+     *
49
+     * @since 3.6.0
50
+     *
51
+     * @param string $post_type The post type, e.g. entity.
52
+     * @param string $slug      The entity type slug, if the slug is empty, the default slug will be used.
53
+     */
54
+    public function __construct( $post_type, $slug ) {
55
+
56
+
57
+        $this->post_type = $post_type;
58
+
59
+        // We cannot assign an empty slug to the register_post_type function, therefore if the slug is empty we default
60
+        // to the type name.
61
+        $this->slug = $slug ?: $post_type;
62
+
63
+        self::$instance = $this;
64
+
65
+    }
66
+
67
+    /**
68
+     * Get the entity type service singleton instance.
69
+     *
70
+     * @since 3.6.0
71
+     *
72
+     * @return Wordlift_Entity_Post_Type_Service The entity type service singleton instance.
73
+     */
74
+    public static function get_instance() {
75
+
76
+        return self::$instance;
77
+    }
78
+
79
+    /**
80
+     * Get the entity type slug.
81
+     *
82
+     * @since 3.6.0
83
+     *
84
+     * @return string The entity type slug.
85
+     */
86
+    public function get_slug() {
87
+
88
+        return $this->slug;
89
+    }
90
+
91
+    /**
92
+     * Get the entity post type name.
93
+     *
94
+     * @since 3.6.0
95
+     *
96
+     * @return string The entity post type.
97
+     */
98
+    public function get_post_type() {
99
+
100
+        return $this->post_type;
101
+    }
102
+
103
+
104
+    /**
105
+     * Register the WordLift entity post type. This method is hooked to WordPress' init action.
106
+     *
107
+     * @since 3.6.0
108
+     */
109
+    public function register() {
110
+
111
+        $labels = array(
112
+            'name'               => _x( 'Vocabulary', 'post type general name', 'wordlift' ),
113
+            'singular_name'      => _x( 'Entity', 'post type singular name', 'wordlift' ),
114
+            'add_new'            => _x( 'Add New Entity', 'entity', 'wordlift' ),
115
+            'add_new_item'       => __( 'Add New Entity', 'wordlift' ),
116
+            'edit_item'          => __( 'Edit Entity', 'wordlift' ),
117
+            'new_item'           => __( 'New Entity', 'wordlift' ),
118
+            'all_items'          => __( 'All Entities', 'wordlift' ),
119
+            'view_item'          => __( 'View Entity', 'wordlift' ),
120
+            'search_items'       => __( 'Search in Vocabulary', 'wordlift' ),
121
+            'not_found'          => __( 'No entities found', 'wordlift' ),
122
+            'not_found_in_trash' => __( 'No entities found in the Trash', 'wordlift' ),
123
+            'parent_item_colon'  => '',
124
+            'menu_name'          => __( 'Vocabulary', 'wordlift' ),
125
+        );
126
+
127
+        $args = array(
128
+            'labels'        => $labels,
129
+            'description'   => 'Holds our vocabulary (set of entities) and entity specific data',
130
+            'public'        => true,
131
+            'menu_position' => 20,
132
+            // after the pages menu.
133
+            // Add support for 'authors' and 'revisions':
134
+            // * see https://github.com/insideout10/wordlift-plugin/issues/395
135
+            // * see https://github.com/insideout10/wordlift-plugin/issues/376
136
+            'supports'      => array(
137
+                'title',
138
+                'editor',
139
+                'thumbnail',
140
+                'excerpt',
141
+                'comments',
142
+                'author',
143
+                // Disabling revisions support.
144
+                //
145
+                // See https://github.com/insideout10/wordlift-plugin/issues/462
146
+                // 'revisions',
147
+            ),
148
+            'has_archive'   => true,
149
+            'menu_icon'     => WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-vocabulary-icon.svg',
150
+            // Although we define our slug here, we further manage linking to entities using the Wordlift_Entity_Link_Service.
151
+            'rewrite'       => array( 'slug' => $this->slug ),
152
+        );
153
+
154
+        register_post_type( $this->post_type, $args );
155
+
156
+        // Enable WP's standard `category` taxonomy for entities.
157
+        //
158
+        // While this enables editors to bind entities to the WP posts' category
159
+        // taxonomy, in Wordlift_Category_Taxonomy_Service we also need to alter
160
+        // WP's main category query to include the `entity` post type.
161
+        //
162
+        // See https://github.com/insideout10/wordlift-plugin/issues/442
163
+        register_taxonomy_for_object_type( 'category', $this->post_type );
164
+
165
+    }
166 166
 
167 167
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * @param string $post_type The post type, e.g. entity.
52 52
 	 * @param string $slug      The entity type slug, if the slug is empty, the default slug will be used.
53 53
 	 */
54
-	public function __construct( $post_type, $slug ) {
54
+	public function __construct($post_type, $slug) {
55 55
 
56 56
 
57 57
 		$this->post_type = $post_type;
@@ -109,19 +109,19 @@  discard block
 block discarded – undo
109 109
 	public function register() {
110 110
 
111 111
 		$labels = array(
112
-			'name'               => _x( 'Vocabulary', 'post type general name', 'wordlift' ),
113
-			'singular_name'      => _x( 'Entity', 'post type singular name', 'wordlift' ),
114
-			'add_new'            => _x( 'Add New Entity', 'entity', 'wordlift' ),
115
-			'add_new_item'       => __( 'Add New Entity', 'wordlift' ),
116
-			'edit_item'          => __( 'Edit Entity', 'wordlift' ),
117
-			'new_item'           => __( 'New Entity', 'wordlift' ),
118
-			'all_items'          => __( 'All Entities', 'wordlift' ),
119
-			'view_item'          => __( 'View Entity', 'wordlift' ),
120
-			'search_items'       => __( 'Search in Vocabulary', 'wordlift' ),
121
-			'not_found'          => __( 'No entities found', 'wordlift' ),
122
-			'not_found_in_trash' => __( 'No entities found in the Trash', 'wordlift' ),
112
+			'name'               => _x('Vocabulary', 'post type general name', 'wordlift'),
113
+			'singular_name'      => _x('Entity', 'post type singular name', 'wordlift'),
114
+			'add_new'            => _x('Add New Entity', 'entity', 'wordlift'),
115
+			'add_new_item'       => __('Add New Entity', 'wordlift'),
116
+			'edit_item'          => __('Edit Entity', 'wordlift'),
117
+			'new_item'           => __('New Entity', 'wordlift'),
118
+			'all_items'          => __('All Entities', 'wordlift'),
119
+			'view_item'          => __('View Entity', 'wordlift'),
120
+			'search_items'       => __('Search in Vocabulary', 'wordlift'),
121
+			'not_found'          => __('No entities found', 'wordlift'),
122
+			'not_found_in_trash' => __('No entities found in the Trash', 'wordlift'),
123 123
 			'parent_item_colon'  => '',
124
-			'menu_name'          => __( 'Vocabulary', 'wordlift' ),
124
+			'menu_name'          => __('Vocabulary', 'wordlift'),
125 125
 		);
126 126
 
127 127
 		$args = array(
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
 				// 'revisions',
147 147
 			),
148 148
 			'has_archive'   => true,
149
-			'menu_icon'     => WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-vocabulary-icon.svg',
149
+			'menu_icon'     => WP_CONTENT_URL.'/plugins/wordlift/images/svg/wl-vocabulary-icon.svg',
150 150
 			// Although we define our slug here, we further manage linking to entities using the Wordlift_Entity_Link_Service.
151
-			'rewrite'       => array( 'slug' => $this->slug ),
151
+			'rewrite'       => array('slug' => $this->slug),
152 152
 		);
153 153
 
154
-		register_post_type( $this->post_type, $args );
154
+		register_post_type($this->post_type, $args);
155 155
 
156 156
 		// Enable WP's standard `category` taxonomy for entities.
157 157
 		//
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		// WP's main category query to include the `entity` post type.
161 161
 		//
162 162
 		// See https://github.com/insideout10/wordlift-plugin/issues/442
163
-		register_taxonomy_for_object_type( 'category', $this->post_type );
163
+		register_taxonomy_for_object_type('category', $this->post_type);
164 164
 
165 165
 	}
166 166
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-content-filter-service.php 2 patches
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -18,92 +18,92 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Content_Filter_Service {
20 20
 
21
-	/**
22
-	 * The pattern to find entities in text.
23
-	 *
24
-	 * @since 3.8.0
25
-	 */
26
-	const PATTERN = '/<(\\w+)[^<]*class="([^"]*)"\\sitemid=\"([^"]+)\"[^>]*>([^<]*)<\\/\\1>/i';
27
-
28
-	/**
29
-	 * A {@link Wordlift_Entity_Service} instance.
30
-	 *
31
-	 * @since  3.8.0
32
-	 * @access private
33
-	 * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
34
-	 */
35
-	private $entity_service;
36
-
37
-	/**
38
-	 * Wordlift_Content_Filter_Service constructor.
39
-	 *
40
-	 * @since 3.8.0
41
-	 *
42
-	 * @param $entity_service
43
-	 */
44
-	public function __construct( $entity_service ) {
45
-
46
-		$this->entity_service = $entity_service;
47
-
48
-	}
49
-
50
-	/**
51
-	 * Mangle the content by adding links to the entity pages. This function is
52
-	 * hooked to the 'the_content' WP's filter.
53
-	 *
54
-	 * @since 3.8.0
55
-	 *
56
-	 * @param string $content The content being filtered.
57
-	 *
58
-	 * @return string The filtered content.
59
-	 */
60
-	public function the_content( $content ) {
61
-
62
-		// Replace each match of the entity tag with the entity link. If an error
63
-		// occurs fail silently returning the original content.
64
-		return preg_replace_callback( self::PATTERN, array(
65
-			$this,
66
-			'link',
67
-		), $content ) ?: $content;
68
-	}
69
-
70
-	/**
71
-	 * Get the entity match and replace it with a page link.
72
-	 *
73
-	 * @since 3.8.0
74
-	 *
75
-	 * @param array $matches An array of matches.
76
-	 *
77
-	 * @return string The replaced text with the link to the entity page.
78
-	 */
79
-	private function link( $matches ) {
80
-
81
-		// Get the entity itemid URI and label.
82
-		$css_class = $matches[2];
83
-		$uri       = $matches[3];
84
-		$label     = $matches[4];
85
-
86
-		// Get the entity post by URI.
87
-		if ( null === ( $post = $this->entity_service->get_entity_post_by_uri( $uri ) ) ) {
88
-
89
-			// If the entity post is not found return the label w/o the markup
90
-			// around it.
91
-			//
92
-			// See https://github.com/insideout10/wordlift-plugin/issues/461
93
-			return $label;
94
-		}
95
-
96
-		// If the `wl-no-link` class is set on the text annotation then we return
97
-		// the label with no anchor.
98
-		if ( - 1 < strpos( $css_class, 'wl-no-link' ) ) {
99
-			return $label;
100
-		}
101
-
102
-		// Get the link.
103
-		$link = get_permalink( $post );
104
-
105
-		// Return the link.
106
-		return "<a class='wl-entity-page-link' href='$link'>$label</a>";
107
-	}
21
+    /**
22
+     * The pattern to find entities in text.
23
+     *
24
+     * @since 3.8.0
25
+     */
26
+    const PATTERN = '/<(\\w+)[^<]*class="([^"]*)"\\sitemid=\"([^"]+)\"[^>]*>([^<]*)<\\/\\1>/i';
27
+
28
+    /**
29
+     * A {@link Wordlift_Entity_Service} instance.
30
+     *
31
+     * @since  3.8.0
32
+     * @access private
33
+     * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
34
+     */
35
+    private $entity_service;
36
+
37
+    /**
38
+     * Wordlift_Content_Filter_Service constructor.
39
+     *
40
+     * @since 3.8.0
41
+     *
42
+     * @param $entity_service
43
+     */
44
+    public function __construct( $entity_service ) {
45
+
46
+        $this->entity_service = $entity_service;
47
+
48
+    }
49
+
50
+    /**
51
+     * Mangle the content by adding links to the entity pages. This function is
52
+     * hooked to the 'the_content' WP's filter.
53
+     *
54
+     * @since 3.8.0
55
+     *
56
+     * @param string $content The content being filtered.
57
+     *
58
+     * @return string The filtered content.
59
+     */
60
+    public function the_content( $content ) {
61
+
62
+        // Replace each match of the entity tag with the entity link. If an error
63
+        // occurs fail silently returning the original content.
64
+        return preg_replace_callback( self::PATTERN, array(
65
+            $this,
66
+            'link',
67
+        ), $content ) ?: $content;
68
+    }
69
+
70
+    /**
71
+     * Get the entity match and replace it with a page link.
72
+     *
73
+     * @since 3.8.0
74
+     *
75
+     * @param array $matches An array of matches.
76
+     *
77
+     * @return string The replaced text with the link to the entity page.
78
+     */
79
+    private function link( $matches ) {
80
+
81
+        // Get the entity itemid URI and label.
82
+        $css_class = $matches[2];
83
+        $uri       = $matches[3];
84
+        $label     = $matches[4];
85
+
86
+        // Get the entity post by URI.
87
+        if ( null === ( $post = $this->entity_service->get_entity_post_by_uri( $uri ) ) ) {
88
+
89
+            // If the entity post is not found return the label w/o the markup
90
+            // around it.
91
+            //
92
+            // See https://github.com/insideout10/wordlift-plugin/issues/461
93
+            return $label;
94
+        }
95
+
96
+        // If the `wl-no-link` class is set on the text annotation then we return
97
+        // the label with no anchor.
98
+        if ( - 1 < strpos( $css_class, 'wl-no-link' ) ) {
99
+            return $label;
100
+        }
101
+
102
+        // Get the link.
103
+        $link = get_permalink( $post );
104
+
105
+        // Return the link.
106
+        return "<a class='wl-entity-page-link' href='$link'>$label</a>";
107
+    }
108 108
 
109 109
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 *
42 42
 	 * @param $entity_service
43 43
 	 */
44
-	public function __construct( $entity_service ) {
44
+	public function __construct($entity_service) {
45 45
 
46 46
 		$this->entity_service = $entity_service;
47 47
 
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
 	 *
58 58
 	 * @return string The filtered content.
59 59
 	 */
60
-	public function the_content( $content ) {
60
+	public function the_content($content) {
61 61
 
62 62
 		// Replace each match of the entity tag with the entity link. If an error
63 63
 		// occurs fail silently returning the original content.
64
-		return preg_replace_callback( self::PATTERN, array(
64
+		return preg_replace_callback(self::PATTERN, array(
65 65
 			$this,
66 66
 			'link',
67
-		), $content ) ?: $content;
67
+		), $content) ?: $content;
68 68
 	}
69 69
 
70 70
 	/**
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	 *
77 77
 	 * @return string The replaced text with the link to the entity page.
78 78
 	 */
79
-	private function link( $matches ) {
79
+	private function link($matches) {
80 80
 
81 81
 		// Get the entity itemid URI and label.
82 82
 		$css_class = $matches[2];
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 		$label     = $matches[4];
85 85
 
86 86
 		// Get the entity post by URI.
87
-		if ( null === ( $post = $this->entity_service->get_entity_post_by_uri( $uri ) ) ) {
87
+		if (null === ($post = $this->entity_service->get_entity_post_by_uri($uri))) {
88 88
 
89 89
 			// If the entity post is not found return the label w/o the markup
90 90
 			// around it.
@@ -95,12 +95,12 @@  discard block
 block discarded – undo
95 95
 
96 96
 		// If the `wl-no-link` class is set on the text annotation then we return
97 97
 		// the label with no anchor.
98
-		if ( - 1 < strpos( $css_class, 'wl-no-link' ) ) {
98
+		if ( -1 < strpos($css_class, 'wl-no-link') ) {
99 99
 			return $label;
100 100
 		}
101 101
 
102 102
 		// Get the link.
103
-		$link = get_permalink( $post );
103
+		$link = get_permalink($post);
104 104
 
105 105
 		// Return the link.
106 106
 		return "<a class='wl-entity-page-link' href='$link'>$label</a>";
Please login to merge, or discard this patch.
src/includes/class-wordlift-category-taxonomy-service.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -18,74 +18,74 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Category_Taxonomy_Service {
20 20
 
21
-	/**
22
-	 * The {@link Wordlift_Entity_Post_Type_Service} instance.
23
-	 *
24
-	 * @since  3.11.0
25
-	 * @access private
26
-	 * @var \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance.
27
-	 */
28
-	private $entity_post_type_service;
21
+    /**
22
+     * The {@link Wordlift_Entity_Post_Type_Service} instance.
23
+     *
24
+     * @since  3.11.0
25
+     * @access private
26
+     * @var \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance.
27
+     */
28
+    private $entity_post_type_service;
29 29
 
30
-	/**
31
-	 * Create a {@link Wordlift_Category_Taxonomy_Service} instance.
32
-	 *
33
-	 * @since 3.11.0
34
-	 *
35
-	 * @param \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance.
36
-	 */
37
-	function __construct( $entity_post_type_service ) {
30
+    /**
31
+     * Create a {@link Wordlift_Category_Taxonomy_Service} instance.
32
+     *
33
+     * @since 3.11.0
34
+     *
35
+     * @param \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance.
36
+     */
37
+    function __construct( $entity_post_type_service ) {
38 38
 
39
-		$this->entity_post_type_service = $entity_post_type_service;
39
+        $this->entity_post_type_service = $entity_post_type_service;
40 40
 
41
-	}
41
+    }
42 42
 
43
-	/**
44
-	 * Set the entity post types as one to be included in archive pages.
45
-	 *
46
-	 * In order to have entities show up in standard WP categories (Posts categories)
47
-	 * we configure the `entity` post type, but we also need to alter the main
48
-	 * WP query (which by default queries posts only) to include the `entities`.
49
-	 *
50
-	 * @since 3.11.0
51
-	 *
52
-	 * @param WP_Query $query WP's {@link WP_Query} instance.
53
-	 */
54
-	public function pre_get_posts( $query ) {
43
+    /**
44
+     * Set the entity post types as one to be included in archive pages.
45
+     *
46
+     * In order to have entities show up in standard WP categories (Posts categories)
47
+     * we configure the `entity` post type, but we also need to alter the main
48
+     * WP query (which by default queries posts only) to include the `entities`.
49
+     *
50
+     * @since 3.11.0
51
+     *
52
+     * @param WP_Query $query WP's {@link WP_Query} instance.
53
+     */
54
+    public function pre_get_posts( $query ) {
55 55
 
56
-		// Only for the main query, avoid problems with widgets and what not.
57
-		if ( ! $query->is_main_query() ) {
58
-			return;
59
-		}
56
+        // Only for the main query, avoid problems with widgets and what not.
57
+        if ( ! $query->is_main_query() ) {
58
+            return;
59
+        }
60 60
 
61
-		// We don't want to alter the query if we're in the admin UI, if this is
62
-		// not a category query, or if the `suppress_filters` is set.
63
-		//
64
-		// Note that it is unlikely for `suppress_filter` to be set on the front
65
-		// end, but let's be safe if it is set the calling code assumes no
66
-		// modifications of queries.
67
-		//
68
-		// is_admin is needed, otherwise category based post filters will show
69
-		// both types and at the current release (4.7) it causes PHP errors.
70
-		if ( is_admin() || ! is_category() || ! empty( $query->query_vars['suppress_filters'] ) ) {
71
-			return;
72
-		}
61
+        // We don't want to alter the query if we're in the admin UI, if this is
62
+        // not a category query, or if the `suppress_filters` is set.
63
+        //
64
+        // Note that it is unlikely for `suppress_filter` to be set on the front
65
+        // end, but let's be safe if it is set the calling code assumes no
66
+        // modifications of queries.
67
+        //
68
+        // is_admin is needed, otherwise category based post filters will show
69
+        // both types and at the current release (4.7) it causes PHP errors.
70
+        if ( is_admin() || ! is_category() || ! empty( $query->query_vars['suppress_filters'] ) ) {
71
+            return;
72
+        }
73 73
 
74
-		// Check the current post types, maybe the category archive pages
75
-		// are already associated with other post types.
76
-		//
77
-		// If `post_type` isn't set, WP assumes `post` by default.
78
-		$post_types = (array) ( $query->get( 'post_type' ) ?: 'post' );
74
+        // Check the current post types, maybe the category archive pages
75
+        // are already associated with other post types.
76
+        //
77
+        // If `post_type` isn't set, WP assumes `post` by default.
78
+        $post_types = (array) ( $query->get( 'post_type' ) ?: 'post' );
79 79
 
80
-		// Add the entities post type only if the post post type is used in the query
81
-		// since we only want `entities` to appear alongside posts.
82
-		if ( in_array( 'post', $post_types ) ) {
83
-			$post_types[] = $this->entity_post_type_service->get_post_type();
84
-		}
80
+        // Add the entities post type only if the post post type is used in the query
81
+        // since we only want `entities` to appear alongside posts.
82
+        if ( in_array( 'post', $post_types ) ) {
83
+            $post_types[] = $this->entity_post_type_service->get_post_type();
84
+        }
85 85
 
86
-		// Update the query post types.
87
-		$query->set( 'post_type', $post_types );
86
+        // Update the query post types.
87
+        $query->set( 'post_type', $post_types );
88 88
 
89
-	}
89
+    }
90 90
 
91 91
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 *
35 35
 	 * @param \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance.
36 36
 	 */
37
-	function __construct( $entity_post_type_service ) {
37
+	function __construct($entity_post_type_service) {
38 38
 
39 39
 		$this->entity_post_type_service = $entity_post_type_service;
40 40
 
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @param WP_Query $query WP's {@link WP_Query} instance.
53 53
 	 */
54
-	public function pre_get_posts( $query ) {
54
+	public function pre_get_posts($query) {
55 55
 
56 56
 		// Only for the main query, avoid problems with widgets and what not.
57
-		if ( ! $query->is_main_query() ) {
57
+		if ( ! $query->is_main_query()) {
58 58
 			return;
59 59
 		}
60 60
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 		//
68 68
 		// is_admin is needed, otherwise category based post filters will show
69 69
 		// both types and at the current release (4.7) it causes PHP errors.
70
-		if ( is_admin() || ! is_category() || ! empty( $query->query_vars['suppress_filters'] ) ) {
70
+		if (is_admin() || ! is_category() || ! empty($query->query_vars['suppress_filters'])) {
71 71
 			return;
72 72
 		}
73 73
 
@@ -75,16 +75,16 @@  discard block
 block discarded – undo
75 75
 		// are already associated with other post types.
76 76
 		//
77 77
 		// If `post_type` isn't set, WP assumes `post` by default.
78
-		$post_types = (array) ( $query->get( 'post_type' ) ?: 'post' );
78
+		$post_types = (array) ($query->get('post_type') ?: 'post');
79 79
 
80 80
 		// Add the entities post type only if the post post type is used in the query
81 81
 		// since we only want `entities` to appear alongside posts.
82
-		if ( in_array( 'post', $post_types ) ) {
82
+		if (in_array('post', $post_types)) {
83 83
 			$post_types[] = $this->entity_post_type_service->get_post_type();
84 84
 		}
85 85
 
86 86
 		// Update the query post types.
87
-		$query->set( 'post_type', $post_types );
87
+		$query->set('post_type', $post_types);
88 88
 
89 89
 	}
90 90
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-configuration-service.php 2 patches
Indentation   +317 added lines, -317 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  */
12 12
 
13 13
 if ( ! defined( 'ABSPATH' ) ) {
14
-	exit;
14
+    exit;
15 15
 }
16 16
 
17 17
 /**
@@ -21,321 +21,321 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class Wordlift_Configuration_Service {
23 23
 
24
-	/**
25
-	 * The entity base path option name.
26
-	 *
27
-	 * @since 3.6.0
28
-	 */
29
-	const ENTITY_BASE_PATH_KEY = 'wl_entity_base_path';
30
-
31
-	/**
32
-	 * The skip wizard (admin installation wizard) option name.
33
-	 *
34
-	 * @since 3.9.0
35
-	 */
36
-	const SKIP_WIZARD = 'wl_skip_wizard';
37
-
38
-	/**
39
-	 * WordLift's key option name.
40
-	 *
41
-	 * @since 3.9.0
42
-	 */
43
-	const KEY = 'key';
44
-
45
-	/**
46
-	 * WordLift's configured language option name.
47
-	 *
48
-	 * @since 3.9.0
49
-	 */
50
-	const LANGUAGE = 'site_language';
51
-
52
-	/**
53
-	 * The publisher entity post ID option name.
54
-	 *
55
-	 * @since 3.9.0
56
-	 */
57
-	const PUBLISHER_ID = 'publisher_id';
58
-
59
-	/**
60
-	 * The dataset URI option name
61
-	 *
62
-	 * @since 3.10.0
63
-	 */
64
-	const DATASET_URI = 'redlink_dataset_uri';
65
-
66
-	/**
67
-	 * The Wordlift_Configuration_Service's singleton instance.
68
-	 *
69
-	 * @since  3.6.0
70
-	 *
71
-	 * @access private
72
-	 * @var \Wordlift_Configuration_Service $instance Wordlift_Configuration_Service's singleton instance.
73
-	 */
74
-	private static $instance;
75
-
76
-	/**
77
-	 * Create a Wordlift_Configuration_Service's instance.
78
-	 *
79
-	 * @since 3.6.0
80
-	 */
81
-	public function __construct() {
82
-
83
-		self::$instance = $this;
84
-
85
-	}
86
-
87
-	/**
88
-	 * Get the singleton instance.
89
-	 *
90
-	 * @since 3.6.0
91
-	 *
92
-	 * @return \Wordlift_Configuration_Service
93
-	 */
94
-	public static function get_instance() {
95
-
96
-		return self::$instance;
97
-	}
98
-
99
-	/**
100
-	 * Get a configuration given the option name and a key. The option value is
101
-	 * expected to be an array.
102
-	 *
103
-	 * @since 3.6.0
104
-	 *
105
-	 * @param string $option  The option name.
106
-	 * @param string $key     A key in the option value array.
107
-	 * @param string $default The default value in case the key is not found (by default an empty string).
108
-	 *
109
-	 * @return mixed The configuration value or the default value if not found.
110
-	 */
111
-	private function get( $option, $key, $default = '' ) {
112
-
113
-		$options = get_option( $option, array() );
114
-
115
-		return isset( $options[ $key ] ) ? $options[ $key ] : $default;
116
-	}
117
-
118
-	/**
119
-	 * Set a configuration parameter.
120
-	 *
121
-	 * @since 3.9.0
122
-	 *
123
-	 * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
124
-	 * @param string $key    The value key.
125
-	 * @param mixed  $value  The value.
126
-	 */
127
-	private function set( $option, $key, $value ) {
128
-
129
-		$values         = get_option( $option );
130
-		$values         = isset( $values ) ? $values : array();
131
-		$values[ $key ] = $value;
132
-		update_option( $option, $values );
133
-
134
-	}
135
-
136
-	/**
137
-	 * Get the entity base path, by default 'entity'.
138
-	 *
139
-	 * @since 3.6.0
140
-	 *
141
-	 * @return string The entity base path.
142
-	 */
143
-	public function get_entity_base_path() {
144
-
145
-		return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' );
146
-	}
147
-
148
-	/**
149
-	 * Get the entity base path.
150
-	 *
151
-	 * @since 3.9.0
152
-	 *
153
-	 * @param string $value The entity base path.
154
-	 */
155
-	public function set_entity_base_path( $value ) {
156
-
157
-		$this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value );
158
-	}
159
-
160
-	/**
161
-	 * Whether the installation skip wizard should be skipped.
162
-	 *
163
-	 * @since 3.9.0
164
-	 *
165
-	 * @return bool True if it should be skipped otherwise false.
166
-	 */
167
-	public function is_skip_wizard() {
168
-
169
-		return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false );
170
-	}
171
-
172
-	/**
173
-	 * Set the skip wizard parameter.
174
-	 *
175
-	 * @since 3.9.0
176
-	 *
177
-	 * @param bool $value True to skip the wizard. We expect a boolean value.
178
-	 */
179
-	public function set_skip_wizard( $value ) {
180
-
181
-		$this->set( 'wl_general_settings', self::SKIP_WIZARD, $value === true );
182
-
183
-	}
184
-
185
-	/**
186
-	 * Get WordLift's key.
187
-	 *
188
-	 * @since 3.9.0
189
-	 *
190
-	 * @return WordLift's key or an empty string if not set.
191
-	 */
192
-	public function get_key() {
193
-
194
-		return $this->get( 'wl_general_settings', self::KEY, '' );
195
-	}
196
-
197
-	/**
198
-	 * Set WordLift's key.
199
-	 *
200
-	 * @since 3.9.0
201
-	 *
202
-	 * @param string $value WordLift's key.
203
-	 */
204
-	public function set_key( $value ) {
205
-
206
-		$this->set( 'wl_general_settings', self::KEY, $value );
207
-	}
208
-
209
-	/**
210
-	 * Get WordLift's configured language, by default 'en'.
211
-	 *
212
-	 * Note that WordLift's language is used when writing strings to the Linked Data dataset, not for the analysis.
213
-	 *
214
-	 * @since 3.9.0
215
-	 *
216
-	 * @return string WordLift's configured language code ('en' by default).
217
-	 */
218
-	public function get_language_code() {
219
-
220
-		return $this->get( 'wl_general_settings', self::LANGUAGE, 'en' );
221
-	}
222
-
223
-	/**
224
-	 * Set WordLift's language code, used when storing strings to the Linked Data dataset.
225
-	 *
226
-	 * @since 3.9.0
227
-	 *
228
-	 * @param string $value WordLift's language code.
229
-	 */
230
-	public function set_language_code( $value ) {
231
-
232
-		$this->set( 'wl_general_settings', self::LANGUAGE, $value );
233
-
234
-	}
235
-
236
-	/**
237
-	 * Get the publisher entity post id.
238
-	 *
239
-	 * The publisher entity post id points to an entity post which contains the data for the publisher used in schema.org
240
-	 * Article markup.
241
-	 *
242
-	 * @since 3.9.0
243
-	 *
244
-	 * @return int|NULL The publisher entity post id or NULL if not set.
245
-	 */
246
-	public function get_publisher_id() {
247
-
248
-		return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null );
249
-	}
250
-
251
-	/**
252
-	 * Set the publisher entity post id.
253
-	 *
254
-	 * @since 3.9.0
255
-	 *
256
-	 * @param int $value The publisher entity post id.
257
-	 */
258
-	public function set_publisher_id( $value ) {
259
-
260
-		$this->set( 'wl_general_settings', self::PUBLISHER_ID, $value );
261
-
262
-	}
263
-
264
-	/**
265
-	 * Get the dataset URI.
266
-	 *
267
-	 * @since 3.10.0
268
-	 *
269
-	 * @return string The dataset URI or an empty string if not set.
270
-	 */
271
-	public function get_dataset_uri() {
272
-
273
-		return $this->get( 'wl_advanced_settings', self::DATASET_URI, null );
274
-	}
275
-
276
-	/**
277
-	 * Set the dataset URI.
278
-	 *
279
-	 * @since 3.10.0
280
-	 *
281
-	 * @param string $value The dataset URI.
282
-	 */
283
-	public function set_dataset_uri( $value ) {
284
-
285
-		$this->set( 'wl_advanced_settings', self::DATASET_URI, $value );
286
-	}
287
-
288
-	/**
289
-	 * Intercept the change of the WordLift key in order to set the dataset URI.
290
-	 *
291
-	 * @since 3.11.0
292
-	 *
293
-	 * @param array $old_value The old settings.
294
-	 * @param array $new_value The new settings.
295
-	 */
296
-	public function update_key( $old_value, $new_value ) {
297
-
298
-		// Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed.
299
-		$old_key = isset( $old_value['key'] ) ? $old_value['key'] : '';
300
-		$new_key = isset( $new_value['key'] ) ? $new_value['key'] : '';
301
-
302
-		// If the key hasn't changed, don't do anything.
303
-		// WARN The 'update_option' hook is fired only if the new and old value are not equal
304
-		if ( $old_key === $new_key ) {
305
-			return;
306
-		}
307
-
308
-		// If the key is empty, empty the dataset URI.
309
-		if ( '' === $new_key ) {
310
-			$this->set_dataset_uri( '' );
311
-		}
312
-
313
-		// Request the dataset URI.
314
-		$response = wp_remote_get( $this->get_accounts_by_key_dataset_uri( $new_key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) );
315
-
316
-		// If the response is valid, then set the value.
317
-		if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) {
318
-
319
-			$this->set_dataset_uri( $response['body'] );
320
-
321
-		} else {
322
-			// TO DO User notification is needed here.
323
-		}
324
-
325
-	}
326
-
327
-	/**
328
-	 * Get the API URI to retrieve the dataset URI using the WordLift Key.
329
-	 *
330
-	 * @since 3.11.0
331
-	 *
332
-	 * @param string $key The WordLift key to use.
333
-	 *
334
-	 * @return string The API URI.
335
-	 */
336
-	public function get_accounts_by_key_dataset_uri( $key ) {
337
-
338
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri";
339
-	}
24
+    /**
25
+     * The entity base path option name.
26
+     *
27
+     * @since 3.6.0
28
+     */
29
+    const ENTITY_BASE_PATH_KEY = 'wl_entity_base_path';
30
+
31
+    /**
32
+     * The skip wizard (admin installation wizard) option name.
33
+     *
34
+     * @since 3.9.0
35
+     */
36
+    const SKIP_WIZARD = 'wl_skip_wizard';
37
+
38
+    /**
39
+     * WordLift's key option name.
40
+     *
41
+     * @since 3.9.0
42
+     */
43
+    const KEY = 'key';
44
+
45
+    /**
46
+     * WordLift's configured language option name.
47
+     *
48
+     * @since 3.9.0
49
+     */
50
+    const LANGUAGE = 'site_language';
51
+
52
+    /**
53
+     * The publisher entity post ID option name.
54
+     *
55
+     * @since 3.9.0
56
+     */
57
+    const PUBLISHER_ID = 'publisher_id';
58
+
59
+    /**
60
+     * The dataset URI option name
61
+     *
62
+     * @since 3.10.0
63
+     */
64
+    const DATASET_URI = 'redlink_dataset_uri';
65
+
66
+    /**
67
+     * The Wordlift_Configuration_Service's singleton instance.
68
+     *
69
+     * @since  3.6.0
70
+     *
71
+     * @access private
72
+     * @var \Wordlift_Configuration_Service $instance Wordlift_Configuration_Service's singleton instance.
73
+     */
74
+    private static $instance;
75
+
76
+    /**
77
+     * Create a Wordlift_Configuration_Service's instance.
78
+     *
79
+     * @since 3.6.0
80
+     */
81
+    public function __construct() {
82
+
83
+        self::$instance = $this;
84
+
85
+    }
86
+
87
+    /**
88
+     * Get the singleton instance.
89
+     *
90
+     * @since 3.6.0
91
+     *
92
+     * @return \Wordlift_Configuration_Service
93
+     */
94
+    public static function get_instance() {
95
+
96
+        return self::$instance;
97
+    }
98
+
99
+    /**
100
+     * Get a configuration given the option name and a key. The option value is
101
+     * expected to be an array.
102
+     *
103
+     * @since 3.6.0
104
+     *
105
+     * @param string $option  The option name.
106
+     * @param string $key     A key in the option value array.
107
+     * @param string $default The default value in case the key is not found (by default an empty string).
108
+     *
109
+     * @return mixed The configuration value or the default value if not found.
110
+     */
111
+    private function get( $option, $key, $default = '' ) {
112
+
113
+        $options = get_option( $option, array() );
114
+
115
+        return isset( $options[ $key ] ) ? $options[ $key ] : $default;
116
+    }
117
+
118
+    /**
119
+     * Set a configuration parameter.
120
+     *
121
+     * @since 3.9.0
122
+     *
123
+     * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
124
+     * @param string $key    The value key.
125
+     * @param mixed  $value  The value.
126
+     */
127
+    private function set( $option, $key, $value ) {
128
+
129
+        $values         = get_option( $option );
130
+        $values         = isset( $values ) ? $values : array();
131
+        $values[ $key ] = $value;
132
+        update_option( $option, $values );
133
+
134
+    }
135
+
136
+    /**
137
+     * Get the entity base path, by default 'entity'.
138
+     *
139
+     * @since 3.6.0
140
+     *
141
+     * @return string The entity base path.
142
+     */
143
+    public function get_entity_base_path() {
144
+
145
+        return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' );
146
+    }
147
+
148
+    /**
149
+     * Get the entity base path.
150
+     *
151
+     * @since 3.9.0
152
+     *
153
+     * @param string $value The entity base path.
154
+     */
155
+    public function set_entity_base_path( $value ) {
156
+
157
+        $this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value );
158
+    }
159
+
160
+    /**
161
+     * Whether the installation skip wizard should be skipped.
162
+     *
163
+     * @since 3.9.0
164
+     *
165
+     * @return bool True if it should be skipped otherwise false.
166
+     */
167
+    public function is_skip_wizard() {
168
+
169
+        return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false );
170
+    }
171
+
172
+    /**
173
+     * Set the skip wizard parameter.
174
+     *
175
+     * @since 3.9.0
176
+     *
177
+     * @param bool $value True to skip the wizard. We expect a boolean value.
178
+     */
179
+    public function set_skip_wizard( $value ) {
180
+
181
+        $this->set( 'wl_general_settings', self::SKIP_WIZARD, $value === true );
182
+
183
+    }
184
+
185
+    /**
186
+     * Get WordLift's key.
187
+     *
188
+     * @since 3.9.0
189
+     *
190
+     * @return WordLift's key or an empty string if not set.
191
+     */
192
+    public function get_key() {
193
+
194
+        return $this->get( 'wl_general_settings', self::KEY, '' );
195
+    }
196
+
197
+    /**
198
+     * Set WordLift's key.
199
+     *
200
+     * @since 3.9.0
201
+     *
202
+     * @param string $value WordLift's key.
203
+     */
204
+    public function set_key( $value ) {
205
+
206
+        $this->set( 'wl_general_settings', self::KEY, $value );
207
+    }
208
+
209
+    /**
210
+     * Get WordLift's configured language, by default 'en'.
211
+     *
212
+     * Note that WordLift's language is used when writing strings to the Linked Data dataset, not for the analysis.
213
+     *
214
+     * @since 3.9.0
215
+     *
216
+     * @return string WordLift's configured language code ('en' by default).
217
+     */
218
+    public function get_language_code() {
219
+
220
+        return $this->get( 'wl_general_settings', self::LANGUAGE, 'en' );
221
+    }
222
+
223
+    /**
224
+     * Set WordLift's language code, used when storing strings to the Linked Data dataset.
225
+     *
226
+     * @since 3.9.0
227
+     *
228
+     * @param string $value WordLift's language code.
229
+     */
230
+    public function set_language_code( $value ) {
231
+
232
+        $this->set( 'wl_general_settings', self::LANGUAGE, $value );
233
+
234
+    }
235
+
236
+    /**
237
+     * Get the publisher entity post id.
238
+     *
239
+     * The publisher entity post id points to an entity post which contains the data for the publisher used in schema.org
240
+     * Article markup.
241
+     *
242
+     * @since 3.9.0
243
+     *
244
+     * @return int|NULL The publisher entity post id or NULL if not set.
245
+     */
246
+    public function get_publisher_id() {
247
+
248
+        return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null );
249
+    }
250
+
251
+    /**
252
+     * Set the publisher entity post id.
253
+     *
254
+     * @since 3.9.0
255
+     *
256
+     * @param int $value The publisher entity post id.
257
+     */
258
+    public function set_publisher_id( $value ) {
259
+
260
+        $this->set( 'wl_general_settings', self::PUBLISHER_ID, $value );
261
+
262
+    }
263
+
264
+    /**
265
+     * Get the dataset URI.
266
+     *
267
+     * @since 3.10.0
268
+     *
269
+     * @return string The dataset URI or an empty string if not set.
270
+     */
271
+    public function get_dataset_uri() {
272
+
273
+        return $this->get( 'wl_advanced_settings', self::DATASET_URI, null );
274
+    }
275
+
276
+    /**
277
+     * Set the dataset URI.
278
+     *
279
+     * @since 3.10.0
280
+     *
281
+     * @param string $value The dataset URI.
282
+     */
283
+    public function set_dataset_uri( $value ) {
284
+
285
+        $this->set( 'wl_advanced_settings', self::DATASET_URI, $value );
286
+    }
287
+
288
+    /**
289
+     * Intercept the change of the WordLift key in order to set the dataset URI.
290
+     *
291
+     * @since 3.11.0
292
+     *
293
+     * @param array $old_value The old settings.
294
+     * @param array $new_value The new settings.
295
+     */
296
+    public function update_key( $old_value, $new_value ) {
297
+
298
+        // Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed.
299
+        $old_key = isset( $old_value['key'] ) ? $old_value['key'] : '';
300
+        $new_key = isset( $new_value['key'] ) ? $new_value['key'] : '';
301
+
302
+        // If the key hasn't changed, don't do anything.
303
+        // WARN The 'update_option' hook is fired only if the new and old value are not equal
304
+        if ( $old_key === $new_key ) {
305
+            return;
306
+        }
307
+
308
+        // If the key is empty, empty the dataset URI.
309
+        if ( '' === $new_key ) {
310
+            $this->set_dataset_uri( '' );
311
+        }
312
+
313
+        // Request the dataset URI.
314
+        $response = wp_remote_get( $this->get_accounts_by_key_dataset_uri( $new_key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) );
315
+
316
+        // If the response is valid, then set the value.
317
+        if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) {
318
+
319
+            $this->set_dataset_uri( $response['body'] );
320
+
321
+        } else {
322
+            // TO DO User notification is needed here.
323
+        }
324
+
325
+    }
326
+
327
+    /**
328
+     * Get the API URI to retrieve the dataset URI using the WordLift Key.
329
+     *
330
+     * @since 3.11.0
331
+     *
332
+     * @param string $key The WordLift key to use.
333
+     *
334
+     * @return string The API URI.
335
+     */
336
+    public function get_accounts_by_key_dataset_uri( $key ) {
337
+
338
+        return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri";
339
+    }
340 340
 
341 341
 }
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @since      3.6.0
11 11
  */
12 12
 
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -108,11 +108,11 @@  discard block
 block discarded – undo
108 108
 	 *
109 109
 	 * @return mixed The configuration value or the default value if not found.
110 110
 	 */
111
-	private function get( $option, $key, $default = '' ) {
111
+	private function get($option, $key, $default = '') {
112 112
 
113
-		$options = get_option( $option, array() );
113
+		$options = get_option($option, array());
114 114
 
115
-		return isset( $options[ $key ] ) ? $options[ $key ] : $default;
115
+		return isset($options[$key]) ? $options[$key] : $default;
116 116
 	}
117 117
 
118 118
 	/**
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
 	 * @param string $key    The value key.
125 125
 	 * @param mixed  $value  The value.
126 126
 	 */
127
-	private function set( $option, $key, $value ) {
127
+	private function set($option, $key, $value) {
128 128
 
129
-		$values         = get_option( $option );
130
-		$values         = isset( $values ) ? $values : array();
131
-		$values[ $key ] = $value;
132
-		update_option( $option, $values );
129
+		$values         = get_option($option);
130
+		$values         = isset($values) ? $values : array();
131
+		$values[$key] = $value;
132
+		update_option($option, $values);
133 133
 
134 134
 	}
135 135
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	 */
143 143
 	public function get_entity_base_path() {
144 144
 
145
-		return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' );
145
+		return $this->get('wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity');
146 146
 	}
147 147
 
148 148
 	/**
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 	 *
153 153
 	 * @param string $value The entity base path.
154 154
 	 */
155
-	public function set_entity_base_path( $value ) {
155
+	public function set_entity_base_path($value) {
156 156
 
157
-		$this->set( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value );
157
+		$this->set('wl_general_settings', self::ENTITY_BASE_PATH_KEY, $value);
158 158
 	}
159 159
 
160 160
 	/**
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	 */
167 167
 	public function is_skip_wizard() {
168 168
 
169
-		return $this->get( 'wl_general_settings', self::SKIP_WIZARD, false );
169
+		return $this->get('wl_general_settings', self::SKIP_WIZARD, false);
170 170
 	}
171 171
 
172 172
 	/**
@@ -176,9 +176,9 @@  discard block
 block discarded – undo
176 176
 	 *
177 177
 	 * @param bool $value True to skip the wizard. We expect a boolean value.
178 178
 	 */
179
-	public function set_skip_wizard( $value ) {
179
+	public function set_skip_wizard($value) {
180 180
 
181
-		$this->set( 'wl_general_settings', self::SKIP_WIZARD, $value === true );
181
+		$this->set('wl_general_settings', self::SKIP_WIZARD, $value === true);
182 182
 
183 183
 	}
184 184
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	 */
192 192
 	public function get_key() {
193 193
 
194
-		return $this->get( 'wl_general_settings', self::KEY, '' );
194
+		return $this->get('wl_general_settings', self::KEY, '');
195 195
 	}
196 196
 
197 197
 	/**
@@ -201,9 +201,9 @@  discard block
 block discarded – undo
201 201
 	 *
202 202
 	 * @param string $value WordLift's key.
203 203
 	 */
204
-	public function set_key( $value ) {
204
+	public function set_key($value) {
205 205
 
206
-		$this->set( 'wl_general_settings', self::KEY, $value );
206
+		$this->set('wl_general_settings', self::KEY, $value);
207 207
 	}
208 208
 
209 209
 	/**
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	 */
218 218
 	public function get_language_code() {
219 219
 
220
-		return $this->get( 'wl_general_settings', self::LANGUAGE, 'en' );
220
+		return $this->get('wl_general_settings', self::LANGUAGE, 'en');
221 221
 	}
222 222
 
223 223
 	/**
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
 	 *
228 228
 	 * @param string $value WordLift's language code.
229 229
 	 */
230
-	public function set_language_code( $value ) {
230
+	public function set_language_code($value) {
231 231
 
232
-		$this->set( 'wl_general_settings', self::LANGUAGE, $value );
232
+		$this->set('wl_general_settings', self::LANGUAGE, $value);
233 233
 
234 234
 	}
235 235
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 	 */
246 246
 	public function get_publisher_id() {
247 247
 
248
-		return $this->get( 'wl_general_settings', self::PUBLISHER_ID, null );
248
+		return $this->get('wl_general_settings', self::PUBLISHER_ID, null);
249 249
 	}
250 250
 
251 251
 	/**
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
 	 *
256 256
 	 * @param int $value The publisher entity post id.
257 257
 	 */
258
-	public function set_publisher_id( $value ) {
258
+	public function set_publisher_id($value) {
259 259
 
260
-		$this->set( 'wl_general_settings', self::PUBLISHER_ID, $value );
260
+		$this->set('wl_general_settings', self::PUBLISHER_ID, $value);
261 261
 
262 262
 	}
263 263
 
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	 */
271 271
 	public function get_dataset_uri() {
272 272
 
273
-		return $this->get( 'wl_advanced_settings', self::DATASET_URI, null );
273
+		return $this->get('wl_advanced_settings', self::DATASET_URI, null);
274 274
 	}
275 275
 
276 276
 	/**
@@ -280,9 +280,9 @@  discard block
 block discarded – undo
280 280
 	 *
281 281
 	 * @param string $value The dataset URI.
282 282
 	 */
283
-	public function set_dataset_uri( $value ) {
283
+	public function set_dataset_uri($value) {
284 284
 
285
-		$this->set( 'wl_advanced_settings', self::DATASET_URI, $value );
285
+		$this->set('wl_advanced_settings', self::DATASET_URI, $value);
286 286
 	}
287 287
 
288 288
 	/**
@@ -293,30 +293,30 @@  discard block
 block discarded – undo
293 293
 	 * @param array $old_value The old settings.
294 294
 	 * @param array $new_value The new settings.
295 295
 	 */
296
-	public function update_key( $old_value, $new_value ) {
296
+	public function update_key($old_value, $new_value) {
297 297
 
298 298
 		// Check the old key value and the new one. We're going to ask for the dataset URI only if the key has changed.
299
-		$old_key = isset( $old_value['key'] ) ? $old_value['key'] : '';
300
-		$new_key = isset( $new_value['key'] ) ? $new_value['key'] : '';
299
+		$old_key = isset($old_value['key']) ? $old_value['key'] : '';
300
+		$new_key = isset($new_value['key']) ? $new_value['key'] : '';
301 301
 
302 302
 		// If the key hasn't changed, don't do anything.
303 303
 		// WARN The 'update_option' hook is fired only if the new and old value are not equal
304
-		if ( $old_key === $new_key ) {
304
+		if ($old_key === $new_key) {
305 305
 			return;
306 306
 		}
307 307
 
308 308
 		// If the key is empty, empty the dataset URI.
309
-		if ( '' === $new_key ) {
310
-			$this->set_dataset_uri( '' );
309
+		if ('' === $new_key) {
310
+			$this->set_dataset_uri('');
311 311
 		}
312 312
 
313 313
 		// Request the dataset URI.
314
-		$response = wp_remote_get( $this->get_accounts_by_key_dataset_uri( $new_key ), unserialize( WL_REDLINK_API_HTTP_OPTIONS ) );
314
+		$response = wp_remote_get($this->get_accounts_by_key_dataset_uri($new_key), unserialize(WL_REDLINK_API_HTTP_OPTIONS));
315 315
 
316 316
 		// If the response is valid, then set the value.
317
-		if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) {
317
+		if ( ! is_wp_error($response) && 200 === (int) $response['response']['code']) {
318 318
 
319
-			$this->set_dataset_uri( $response['body'] );
319
+			$this->set_dataset_uri($response['body']);
320 320
 
321 321
 		} else {
322 322
 			// TO DO User notification is needed here.
@@ -333,9 +333,9 @@  discard block
 block discarded – undo
333 333
 	 *
334 334
 	 * @return string The API URI.
335 335
 	 */
336
-	public function get_accounts_by_key_dataset_uri( $key ) {
336
+	public function get_accounts_by_key_dataset_uri($key) {
337 337
 
338
-		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE . "accounts/key=$key/dataset_uri";
338
+		return WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE."accounts/key=$key/dataset_uri";
339 339
 	}
340 340
 
341 341
 }
Please login to merge, or discard this patch.