@@ -5,125 +5,125 @@ discard block |
||
| 5 | 5 | |
| 6 | 6 | class Wordlift_Admin_Dashboard_V2 { |
| 7 | 7 | |
| 8 | - const TODAYS_TIP = 'wl_todays_tip_data'; |
|
| 9 | - const AVERAGE_POSITION = 'wl_search_rankings_average_position'; |
|
| 10 | - |
|
| 11 | - /** |
|
| 12 | - * The {@link Wordlift_Admin_Search_Rankings_Service} instance. |
|
| 13 | - * |
|
| 14 | - * @since 3.20.0 |
|
| 15 | - * @access private |
|
| 16 | - * @var \Wordlift_Admin_Search_Rankings_Service $search_rankings_service The {@link Wordlift_Admin_Search_Rankings_Service} instance. |
|
| 17 | - */ |
|
| 18 | - private $search_rankings_service; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * The {@link Wordlift_Dashboard_Service} instance. |
|
| 22 | - * |
|
| 23 | - * @var \Wordlift_Dashboard_Service $dashboard_service The {@link Wordlift_Dashboard_Service} instance. |
|
| 24 | - * @access private |
|
| 25 | - * @since 3.20.0 |
|
| 26 | - */ |
|
| 27 | - private $dashboard_service; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var \Wordlift_Entity_Service $entity_service |
|
| 31 | - */ |
|
| 32 | - private $entity_service; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Wordlift_Admin_Dashboard_V2 constructor. |
|
| 36 | - * |
|
| 37 | - * @since 3.20.0 |
|
| 38 | - * |
|
| 39 | - * @param \Wordlift_Admin_Search_Rankings_Service $search_rankings_service The {@link Wordlift_Admin_Search_Rankings_Service} instance. |
|
| 40 | - * @param $dashboard_service |
|
| 41 | - */ |
|
| 42 | - public function __construct( $search_rankings_service, $dashboard_service, $entity_service ) { |
|
| 43 | - |
|
| 44 | - add_action( 'wp_dashboard_setup', array( $this, 'dashboard_setup' ) ); |
|
| 45 | - |
|
| 46 | - // Define where to access the tip. |
|
| 47 | - defined( 'WL_TODAYS_TIP_JSON_URL' ) || define( 'WL_TODAYS_TIP_JSON_URL', 'https://wordlift.io/blog' ); |
|
| 48 | - defined( 'WL_TODAYS_TIP_JSON_URL_IT' ) || define( 'WL_TODAYS_TIP_JSON_URL_IT', '/it/wp-json/wp/v2/posts?context=embed&per_page=1&categories=27' ); |
|
| 49 | - defined( 'WL_TODAYS_TIP_JSON_URL_EN' ) || define( 'WL_TODAYS_TIP_JSON_URL_EN', '/en/wp-json/wp/v2/posts?context=embed&per_page=1&categories=38' ); |
|
| 50 | - |
|
| 51 | - $this->search_rankings_service = $search_rankings_service; |
|
| 52 | - $this->dashboard_service = $dashboard_service; |
|
| 53 | - $this->entity_service = $entity_service; |
|
| 54 | - |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Set up the dashboard metabox. |
|
| 59 | - * |
|
| 60 | - * @since 3.20.0 |
|
| 61 | - */ |
|
| 62 | - public function dashboard_setup() { |
|
| 63 | - |
|
| 64 | - wp_add_dashboard_widget( |
|
| 65 | - 'wl-dashboard-v2', |
|
| 66 | - __( 'WordLift Dashboard', 'wordlift' ), |
|
| 67 | - array( $this, 'dashboard_setup_callback' ) |
|
| 68 | - ); |
|
| 69 | - |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * The dashboard setup callback. |
|
| 74 | - * |
|
| 75 | - * @since 3.20.0 |
|
| 76 | - */ |
|
| 77 | - public function dashboard_setup_callback() { |
|
| 78 | - |
|
| 79 | - // Get the average position. |
|
| 80 | - $average_position_string = $this->get_average_position(); |
|
| 81 | - |
|
| 82 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-dashboard-v2.php'; |
|
| 83 | - |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Get the keyword average position. |
|
| 88 | - * |
|
| 89 | - * @since 3.20.0 |
|
| 90 | - * |
|
| 91 | - * @return string The formatted average position string (or `n/a` if not available). |
|
| 92 | - */ |
|
| 93 | - private function get_average_position() { |
|
| 94 | - |
|
| 95 | - // Get the cache value. |
|
| 96 | - $average_position = get_transient( self::AVERAGE_POSITION ); |
|
| 97 | - |
|
| 98 | - // If there's no cached value, load it. |
|
| 99 | - if ( false === $average_position ) { |
|
| 100 | - // Get the average position from Search Ranking Service. |
|
| 101 | - $average_position = @$this->search_rankings_service->get_average_position(); |
|
| 102 | - |
|
| 103 | - // If there was an error return 'n/a'. |
|
| 104 | - if ( false === $average_position ) { |
|
| 105 | - return esc_html( _x( 'n/a', 'Dashboard', 'wordlift' ) ); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // Store the value for one day. |
|
| 110 | - set_transient( self::AVERAGE_POSITION, $average_position, 86400 ); // One day. |
|
| 111 | - |
|
| 112 | - // Format the average position with one decimal. |
|
| 113 | - return number_format( $average_position, 1 ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Get the top entities. |
|
| 118 | - * |
|
| 119 | - * @since 3.20.0 |
|
| 120 | - * |
|
| 121 | - * @return array|object|null An array of top entities. |
|
| 122 | - */ |
|
| 123 | - private function get_top_entities() { |
|
| 124 | - global $wpdb; |
|
| 125 | - |
|
| 126 | - $query = <<<EOF |
|
| 8 | + const TODAYS_TIP = 'wl_todays_tip_data'; |
|
| 9 | + const AVERAGE_POSITION = 'wl_search_rankings_average_position'; |
|
| 10 | + |
|
| 11 | + /** |
|
| 12 | + * The {@link Wordlift_Admin_Search_Rankings_Service} instance. |
|
| 13 | + * |
|
| 14 | + * @since 3.20.0 |
|
| 15 | + * @access private |
|
| 16 | + * @var \Wordlift_Admin_Search_Rankings_Service $search_rankings_service The {@link Wordlift_Admin_Search_Rankings_Service} instance. |
|
| 17 | + */ |
|
| 18 | + private $search_rankings_service; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * The {@link Wordlift_Dashboard_Service} instance. |
|
| 22 | + * |
|
| 23 | + * @var \Wordlift_Dashboard_Service $dashboard_service The {@link Wordlift_Dashboard_Service} instance. |
|
| 24 | + * @access private |
|
| 25 | + * @since 3.20.0 |
|
| 26 | + */ |
|
| 27 | + private $dashboard_service; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var \Wordlift_Entity_Service $entity_service |
|
| 31 | + */ |
|
| 32 | + private $entity_service; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Wordlift_Admin_Dashboard_V2 constructor. |
|
| 36 | + * |
|
| 37 | + * @since 3.20.0 |
|
| 38 | + * |
|
| 39 | + * @param \Wordlift_Admin_Search_Rankings_Service $search_rankings_service The {@link Wordlift_Admin_Search_Rankings_Service} instance. |
|
| 40 | + * @param $dashboard_service |
|
| 41 | + */ |
|
| 42 | + public function __construct( $search_rankings_service, $dashboard_service, $entity_service ) { |
|
| 43 | + |
|
| 44 | + add_action( 'wp_dashboard_setup', array( $this, 'dashboard_setup' ) ); |
|
| 45 | + |
|
| 46 | + // Define where to access the tip. |
|
| 47 | + defined( 'WL_TODAYS_TIP_JSON_URL' ) || define( 'WL_TODAYS_TIP_JSON_URL', 'https://wordlift.io/blog' ); |
|
| 48 | + defined( 'WL_TODAYS_TIP_JSON_URL_IT' ) || define( 'WL_TODAYS_TIP_JSON_URL_IT', '/it/wp-json/wp/v2/posts?context=embed&per_page=1&categories=27' ); |
|
| 49 | + defined( 'WL_TODAYS_TIP_JSON_URL_EN' ) || define( 'WL_TODAYS_TIP_JSON_URL_EN', '/en/wp-json/wp/v2/posts?context=embed&per_page=1&categories=38' ); |
|
| 50 | + |
|
| 51 | + $this->search_rankings_service = $search_rankings_service; |
|
| 52 | + $this->dashboard_service = $dashboard_service; |
|
| 53 | + $this->entity_service = $entity_service; |
|
| 54 | + |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Set up the dashboard metabox. |
|
| 59 | + * |
|
| 60 | + * @since 3.20.0 |
|
| 61 | + */ |
|
| 62 | + public function dashboard_setup() { |
|
| 63 | + |
|
| 64 | + wp_add_dashboard_widget( |
|
| 65 | + 'wl-dashboard-v2', |
|
| 66 | + __( 'WordLift Dashboard', 'wordlift' ), |
|
| 67 | + array( $this, 'dashboard_setup_callback' ) |
|
| 68 | + ); |
|
| 69 | + |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * The dashboard setup callback. |
|
| 74 | + * |
|
| 75 | + * @since 3.20.0 |
|
| 76 | + */ |
|
| 77 | + public function dashboard_setup_callback() { |
|
| 78 | + |
|
| 79 | + // Get the average position. |
|
| 80 | + $average_position_string = $this->get_average_position(); |
|
| 81 | + |
|
| 82 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-dashboard-v2.php'; |
|
| 83 | + |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Get the keyword average position. |
|
| 88 | + * |
|
| 89 | + * @since 3.20.0 |
|
| 90 | + * |
|
| 91 | + * @return string The formatted average position string (or `n/a` if not available). |
|
| 92 | + */ |
|
| 93 | + private function get_average_position() { |
|
| 94 | + |
|
| 95 | + // Get the cache value. |
|
| 96 | + $average_position = get_transient( self::AVERAGE_POSITION ); |
|
| 97 | + |
|
| 98 | + // If there's no cached value, load it. |
|
| 99 | + if ( false === $average_position ) { |
|
| 100 | + // Get the average position from Search Ranking Service. |
|
| 101 | + $average_position = @$this->search_rankings_service->get_average_position(); |
|
| 102 | + |
|
| 103 | + // If there was an error return 'n/a'. |
|
| 104 | + if ( false === $average_position ) { |
|
| 105 | + return esc_html( _x( 'n/a', 'Dashboard', 'wordlift' ) ); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // Store the value for one day. |
|
| 110 | + set_transient( self::AVERAGE_POSITION, $average_position, 86400 ); // One day. |
|
| 111 | + |
|
| 112 | + // Format the average position with one decimal. |
|
| 113 | + return number_format( $average_position, 1 ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Get the top entities. |
|
| 118 | + * |
|
| 119 | + * @since 3.20.0 |
|
| 120 | + * |
|
| 121 | + * @return array|object|null An array of top entities. |
|
| 122 | + */ |
|
| 123 | + private function get_top_entities() { |
|
| 124 | + global $wpdb; |
|
| 125 | + |
|
| 126 | + $query = <<<EOF |
|
| 127 | 127 | select p.ID |
| 128 | 128 | , p.post_title |
| 129 | 129 | , coalesce(sum(case when obj_t.slug is null then 1 end), 0) entities |
@@ -153,23 +153,23 @@ discard block |
||
| 153 | 153 | limit 100; |
| 154 | 154 | EOF; |
| 155 | 155 | |
| 156 | - return $wpdb->get_results( $query ); |
|
| 157 | - } |
|
| 156 | + return $wpdb->get_results( $query ); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * Get the today's tip block. |
|
| 161 | - * |
|
| 162 | - * @since 3.20.0 |
|
| 163 | - */ |
|
| 164 | - public static function get_todays_tip_block() { |
|
| 159 | + /** |
|
| 160 | + * Get the today's tip block. |
|
| 161 | + * |
|
| 162 | + * @since 3.20.0 |
|
| 163 | + */ |
|
| 164 | + public static function get_todays_tip_block() { |
|
| 165 | 165 | |
| 166 | - $data = @self::get_todays_tip_data(); |
|
| 166 | + $data = @self::get_todays_tip_data(); |
|
| 167 | 167 | |
| 168 | - // Unable to get data from the local cache, nor from the remote URL. |
|
| 169 | - if ( false === $data ) { |
|
| 170 | - return; |
|
| 171 | - } |
|
| 172 | - ?> |
|
| 168 | + // Unable to get data from the local cache, nor from the remote URL. |
|
| 169 | + if ( false === $data ) { |
|
| 170 | + return; |
|
| 171 | + } |
|
| 172 | + ?> |
|
| 173 | 173 | |
| 174 | 174 | <div id="wl-todays-tip" class="wl-dashboard__block wl-dashboard__block--todays-tip"> |
| 175 | 175 | <header> |
@@ -184,53 +184,53 @@ discard block |
||
| 184 | 184 | </div> |
| 185 | 185 | <?php |
| 186 | 186 | |
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Get the today's tip data. |
|
| 191 | - * |
|
| 192 | - * @since 3.20.0 |
|
| 193 | - * |
|
| 194 | - * @return array|false The today's tip data or false in case of error. |
|
| 195 | - */ |
|
| 196 | - private static function get_todays_tip_data() { |
|
| 197 | - |
|
| 198 | - // Return the transient. |
|
| 199 | - if ( false !== get_transient( self::TODAYS_TIP ) ) { |
|
| 200 | - return get_transient( self::TODAYS_TIP ); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - // If the transient isn't available, query the remote web site. |
|
| 204 | - $url = WL_TODAYS_TIP_JSON_URL |
|
| 205 | - . ( 'it' === get_bloginfo( 'language' ) ? WL_TODAYS_TIP_JSON_URL_IT : WL_TODAYS_TIP_JSON_URL_EN ); |
|
| 206 | - |
|
| 207 | - $response = wp_remote_get( $url ); |
|
| 208 | - |
|
| 209 | - if ( is_wp_error( $response ) |
|
| 210 | - || ! isset( $response['response']['code'] ) |
|
| 211 | - || 2 !== (int) $response['response']['code'] / 100 ) { |
|
| 212 | - return false; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - $json = json_decode( $response['body'], true ); |
|
| 216 | - |
|
| 217 | - if ( empty( $json ) |
|
| 218 | - || ! isset( $json[0]['title']['rendered'] ) |
|
| 219 | - || ! isset( $json[0]['excerpt']['rendered'] ) |
|
| 220 | - || ! isset( $json[0]['link'] ) ) { |
|
| 221 | - return false; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - $value = array( |
|
| 225 | - 'title' => $json[0]['title']['rendered'], |
|
| 226 | - 'excerpt' => '<!-- cached -->' . $json[0]['excerpt']['rendered'], |
|
| 227 | - 'link' => $json[0]['link'], |
|
| 228 | - ); |
|
| 229 | - |
|
| 230 | - // Store the results for one day. |
|
| 231 | - set_transient( self::TODAYS_TIP, $value, 86400 ); |
|
| 232 | - |
|
| 233 | - return $value; |
|
| 234 | - } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Get the today's tip data. |
|
| 191 | + * |
|
| 192 | + * @since 3.20.0 |
|
| 193 | + * |
|
| 194 | + * @return array|false The today's tip data or false in case of error. |
|
| 195 | + */ |
|
| 196 | + private static function get_todays_tip_data() { |
|
| 197 | + |
|
| 198 | + // Return the transient. |
|
| 199 | + if ( false !== get_transient( self::TODAYS_TIP ) ) { |
|
| 200 | + return get_transient( self::TODAYS_TIP ); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + // If the transient isn't available, query the remote web site. |
|
| 204 | + $url = WL_TODAYS_TIP_JSON_URL |
|
| 205 | + . ( 'it' === get_bloginfo( 'language' ) ? WL_TODAYS_TIP_JSON_URL_IT : WL_TODAYS_TIP_JSON_URL_EN ); |
|
| 206 | + |
|
| 207 | + $response = wp_remote_get( $url ); |
|
| 208 | + |
|
| 209 | + if ( is_wp_error( $response ) |
|
| 210 | + || ! isset( $response['response']['code'] ) |
|
| 211 | + || 2 !== (int) $response['response']['code'] / 100 ) { |
|
| 212 | + return false; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + $json = json_decode( $response['body'], true ); |
|
| 216 | + |
|
| 217 | + if ( empty( $json ) |
|
| 218 | + || ! isset( $json[0]['title']['rendered'] ) |
|
| 219 | + || ! isset( $json[0]['excerpt']['rendered'] ) |
|
| 220 | + || ! isset( $json[0]['link'] ) ) { |
|
| 221 | + return false; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + $value = array( |
|
| 225 | + 'title' => $json[0]['title']['rendered'], |
|
| 226 | + 'excerpt' => '<!-- cached -->' . $json[0]['excerpt']['rendered'], |
|
| 227 | + 'link' => $json[0]['link'], |
|
| 228 | + ); |
|
| 229 | + |
|
| 230 | + // Store the results for one day. |
|
| 231 | + set_transient( self::TODAYS_TIP, $value, 86400 ); |
|
| 232 | + |
|
| 233 | + return $value; |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | 236 | } |
@@ -39,14 +39,14 @@ discard block |
||
| 39 | 39 | * @param \Wordlift_Admin_Search_Rankings_Service $search_rankings_service The {@link Wordlift_Admin_Search_Rankings_Service} instance. |
| 40 | 40 | * @param $dashboard_service |
| 41 | 41 | */ |
| 42 | - public function __construct( $search_rankings_service, $dashboard_service, $entity_service ) { |
|
| 42 | + public function __construct($search_rankings_service, $dashboard_service, $entity_service) { |
|
| 43 | 43 | |
| 44 | - add_action( 'wp_dashboard_setup', array( $this, 'dashboard_setup' ) ); |
|
| 44 | + add_action('wp_dashboard_setup', array($this, 'dashboard_setup')); |
|
| 45 | 45 | |
| 46 | 46 | // Define where to access the tip. |
| 47 | - defined( 'WL_TODAYS_TIP_JSON_URL' ) || define( 'WL_TODAYS_TIP_JSON_URL', 'https://wordlift.io/blog' ); |
|
| 48 | - defined( 'WL_TODAYS_TIP_JSON_URL_IT' ) || define( 'WL_TODAYS_TIP_JSON_URL_IT', '/it/wp-json/wp/v2/posts?context=embed&per_page=1&categories=27' ); |
|
| 49 | - defined( 'WL_TODAYS_TIP_JSON_URL_EN' ) || define( 'WL_TODAYS_TIP_JSON_URL_EN', '/en/wp-json/wp/v2/posts?context=embed&per_page=1&categories=38' ); |
|
| 47 | + defined('WL_TODAYS_TIP_JSON_URL') || define('WL_TODAYS_TIP_JSON_URL', 'https://wordlift.io/blog'); |
|
| 48 | + defined('WL_TODAYS_TIP_JSON_URL_IT') || define('WL_TODAYS_TIP_JSON_URL_IT', '/it/wp-json/wp/v2/posts?context=embed&per_page=1&categories=27'); |
|
| 49 | + defined('WL_TODAYS_TIP_JSON_URL_EN') || define('WL_TODAYS_TIP_JSON_URL_EN', '/en/wp-json/wp/v2/posts?context=embed&per_page=1&categories=38'); |
|
| 50 | 50 | |
| 51 | 51 | $this->search_rankings_service = $search_rankings_service; |
| 52 | 52 | $this->dashboard_service = $dashboard_service; |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | wp_add_dashboard_widget( |
| 65 | 65 | 'wl-dashboard-v2', |
| 66 | - __( 'WordLift Dashboard', 'wordlift' ), |
|
| 67 | - array( $this, 'dashboard_setup_callback' ) |
|
| 66 | + __('WordLift Dashboard', 'wordlift'), |
|
| 67 | + array($this, 'dashboard_setup_callback') |
|
| 68 | 68 | ); |
| 69 | 69 | |
| 70 | 70 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | // Get the average position. |
| 80 | 80 | $average_position_string = $this->get_average_position(); |
| 81 | 81 | |
| 82 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/wordlift-admin-dashboard-v2.php'; |
|
| 82 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/partials/wordlift-admin-dashboard-v2.php'; |
|
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | |
@@ -93,24 +93,24 @@ discard block |
||
| 93 | 93 | private function get_average_position() { |
| 94 | 94 | |
| 95 | 95 | // Get the cache value. |
| 96 | - $average_position = get_transient( self::AVERAGE_POSITION ); |
|
| 96 | + $average_position = get_transient(self::AVERAGE_POSITION); |
|
| 97 | 97 | |
| 98 | 98 | // If there's no cached value, load it. |
| 99 | - if ( false === $average_position ) { |
|
| 99 | + if (false === $average_position) { |
|
| 100 | 100 | // Get the average position from Search Ranking Service. |
| 101 | 101 | $average_position = @$this->search_rankings_service->get_average_position(); |
| 102 | 102 | |
| 103 | 103 | // If there was an error return 'n/a'. |
| 104 | - if ( false === $average_position ) { |
|
| 105 | - return esc_html( _x( 'n/a', 'Dashboard', 'wordlift' ) ); |
|
| 104 | + if (false === $average_position) { |
|
| 105 | + return esc_html(_x('n/a', 'Dashboard', 'wordlift')); |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // Store the value for one day. |
| 110 | - set_transient( self::AVERAGE_POSITION, $average_position, 86400 ); // One day. |
|
| 110 | + set_transient(self::AVERAGE_POSITION, $average_position, 86400); // One day. |
|
| 111 | 111 | |
| 112 | 112 | // Format the average position with one decimal. |
| 113 | - return number_format( $average_position, 1 ); |
|
| 113 | + return number_format($average_position, 1); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | limit 100; |
| 154 | 154 | EOF; |
| 155 | 155 | |
| 156 | - return $wpdb->get_results( $query ); |
|
| 156 | + return $wpdb->get_results($query); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -166,20 +166,20 @@ discard block |
||
| 166 | 166 | $data = @self::get_todays_tip_data(); |
| 167 | 167 | |
| 168 | 168 | // Unable to get data from the local cache, nor from the remote URL. |
| 169 | - if ( false === $data ) { |
|
| 169 | + if (false === $data) { |
|
| 170 | 170 | return; |
| 171 | 171 | } |
| 172 | 172 | ?> |
| 173 | 173 | |
| 174 | 174 | <div id="wl-todays-tip" class="wl-dashboard__block wl-dashboard__block--todays-tip"> |
| 175 | 175 | <header> |
| 176 | - <h3><?php echo __( "Today's Tip", 'wordlift' ); ?></h3> |
|
| 176 | + <h3><?php echo __("Today's Tip", 'wordlift'); ?></h3> |
|
| 177 | 177 | </header> |
| 178 | 178 | <article> |
| 179 | - <p><strong><?php echo esc_html( wp_strip_all_tags( $data['title'] ) ); ?></strong> |
|
| 180 | - <?php echo esc_html( wp_strip_all_tags( $data['excerpt'] ) ); ?> |
|
| 179 | + <p><strong><?php echo esc_html(wp_strip_all_tags($data['title'])); ?></strong> |
|
| 180 | + <?php echo esc_html(wp_strip_all_tags($data['excerpt'])); ?> |
|
| 181 | 181 | <a target="_blank" |
| 182 | - href="<?php echo esc_attr( $data['link'] ); ?>"><?php echo esc_html( __( 'Read more', 'wordlift' ) ); ?></a> |
|
| 182 | + href="<?php echo esc_attr($data['link']); ?>"><?php echo esc_html(__('Read more', 'wordlift')); ?></a> |
|
| 183 | 183 | </p> |
| 184 | 184 | </div> |
| 185 | 185 | <?php |
@@ -196,39 +196,39 @@ discard block |
||
| 196 | 196 | private static function get_todays_tip_data() { |
| 197 | 197 | |
| 198 | 198 | // Return the transient. |
| 199 | - if ( false !== get_transient( self::TODAYS_TIP ) ) { |
|
| 200 | - return get_transient( self::TODAYS_TIP ); |
|
| 199 | + if (false !== get_transient(self::TODAYS_TIP)) { |
|
| 200 | + return get_transient(self::TODAYS_TIP); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | // If the transient isn't available, query the remote web site. |
| 204 | 204 | $url = WL_TODAYS_TIP_JSON_URL |
| 205 | - . ( 'it' === get_bloginfo( 'language' ) ? WL_TODAYS_TIP_JSON_URL_IT : WL_TODAYS_TIP_JSON_URL_EN ); |
|
| 205 | + . ('it' === get_bloginfo('language') ? WL_TODAYS_TIP_JSON_URL_IT : WL_TODAYS_TIP_JSON_URL_EN); |
|
| 206 | 206 | |
| 207 | - $response = wp_remote_get( $url ); |
|
| 207 | + $response = wp_remote_get($url); |
|
| 208 | 208 | |
| 209 | - if ( is_wp_error( $response ) |
|
| 210 | - || ! isset( $response['response']['code'] ) |
|
| 211 | - || 2 !== (int) $response['response']['code'] / 100 ) { |
|
| 209 | + if (is_wp_error($response) |
|
| 210 | + || ! isset($response['response']['code']) |
|
| 211 | + || 2 !== (int) $response['response']['code'] / 100) { |
|
| 212 | 212 | return false; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - $json = json_decode( $response['body'], true ); |
|
| 215 | + $json = json_decode($response['body'], true); |
|
| 216 | 216 | |
| 217 | - if ( empty( $json ) |
|
| 218 | - || ! isset( $json[0]['title']['rendered'] ) |
|
| 219 | - || ! isset( $json[0]['excerpt']['rendered'] ) |
|
| 220 | - || ! isset( $json[0]['link'] ) ) { |
|
| 217 | + if (empty($json) |
|
| 218 | + || ! isset($json[0]['title']['rendered']) |
|
| 219 | + || ! isset($json[0]['excerpt']['rendered']) |
|
| 220 | + || ! isset($json[0]['link'])) { |
|
| 221 | 221 | return false; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | $value = array( |
| 225 | 225 | 'title' => $json[0]['title']['rendered'], |
| 226 | - 'excerpt' => '<!-- cached -->' . $json[0]['excerpt']['rendered'], |
|
| 226 | + 'excerpt' => '<!-- cached -->'.$json[0]['excerpt']['rendered'], |
|
| 227 | 227 | 'link' => $json[0]['link'], |
| 228 | 228 | ); |
| 229 | 229 | |
| 230 | 230 | // Store the results for one day. |
| 231 | - set_transient( self::TODAYS_TIP, $value, 86400 ); |
|
| 231 | + set_transient(self::TODAYS_TIP, $value, 86400); |
|
| 232 | 232 | |
| 233 | 233 | return $value; |
| 234 | 234 | } |