Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | use Automattic\Jetpack\Constants; |
||
| 3 | use Automattic\Jetpack\Connection\REST_Connector; |
||
| 4 | use Automattic\Jetpack\Licensing; |
||
| 5 | use Automattic\Jetpack\Partner; |
||
| 6 | use Automattic\Jetpack\Status; |
||
| 7 | |||
| 8 | include_once( 'class.jetpack-admin-page.php' ); |
||
| 9 | |||
| 10 | // Builds the landing page and its menu |
||
| 11 | class Jetpack_React_Page extends Jetpack_Admin_Page { |
||
| 12 | |||
| 13 | protected $dont_show_if_not_active = false; |
||
| 14 | |||
| 15 | protected $is_redirecting = false; |
||
| 16 | |||
| 17 | function get_page_hook() { |
||
| 18 | // Add the main admin Jetpack menu |
||
| 19 | return add_menu_page( 'Jetpack', 'Jetpack', 'jetpack_admin_page', 'jetpack', array( $this, 'render' ), 'div', 3 ); |
||
| 20 | } |
||
| 21 | |||
| 22 | function add_page_actions( $hook ) { |
||
| 23 | /** This action is documented in class.jetpack.php */ |
||
| 24 | do_action( 'jetpack_admin_menu', $hook ); |
||
| 25 | |||
| 26 | if ( ! isset( $_GET['page'] ) || 'jetpack' !== $_GET['page'] ) { |
||
| 27 | return; // No need to handle the fallback redirection if we are not on the Jetpack page |
||
| 28 | } |
||
| 29 | |||
| 30 | // Adding a redirect meta tag if the REST API is disabled |
||
| 31 | if ( ! $this->is_rest_api_enabled() ) { |
||
| 32 | $this->is_redirecting = true; |
||
| 33 | add_action( 'admin_head', array( $this, 'add_fallback_head_meta' ) ); |
||
| 34 | } |
||
| 35 | |||
| 36 | // Adding a redirect meta tag wrapped in noscript tags for all browsers in case they have JavaScript disabled |
||
| 37 | add_action( 'admin_head', array( $this, 'add_noscript_head_meta' ) ); |
||
| 38 | |||
| 39 | // If this is the first time the user is viewing the admin, don't show JITMs. |
||
| 40 | // This filter is added just in time because this function is called on admin_menu |
||
| 41 | // and JITMs are initialized on admin_init |
||
| 42 | if ( Jetpack::is_active() && ! Jetpack_Options::get_option( 'first_admin_view', false ) ) { |
||
| 43 | Jetpack_Options::update_option( 'first_admin_view', true ); |
||
| 44 | add_filter( 'jetpack_just_in_time_msgs', '__return_false' ); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Add Jetpack Setup sub-link for eligible users |
||
| 50 | */ |
||
| 51 | function jetpack_add_set_up_sub_nav_item() { |
||
| 52 | if ( $this->show_setup_wizard() ) { |
||
| 53 | add_submenu_page( 'jetpack', __( 'Set up', 'jetpack' ), __( 'Set up', 'jetpack' ), 'jetpack_admin_page', 'jetpack#/setup', '__return_null' ); |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Add Jetpack Dashboard sub-link and point it to AAG if the user can view stats, manage modules or if Protect is active. |
||
| 59 | * |
||
| 60 | * Works in Dev Mode or when user is connected. |
||
| 61 | * |
||
| 62 | * @since 4.3.0 |
||
| 63 | */ |
||
| 64 | function jetpack_add_dashboard_sub_nav_item() { |
||
| 65 | View Code Duplication | if ( ( new Status() )->is_offline_mode() || Jetpack::is_active() ) { |
|
| 66 | add_submenu_page( 'jetpack', __( 'Dashboard', 'jetpack' ), __( 'Dashboard', 'jetpack' ), 'jetpack_admin_page', 'jetpack#/dashboard', '__return_null' ); |
||
| 67 | remove_submenu_page( 'jetpack', 'jetpack' ); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * If user is allowed to see the Jetpack Admin, add Settings sub-link. |
||
| 73 | * |
||
| 74 | * @since 4.3.0 |
||
| 75 | */ |
||
| 76 | function jetpack_add_settings_sub_nav_item() { |
||
| 77 | View Code Duplication | if ( ( ( new Status() )->is_offline_mode() || Jetpack::is_active() ) && current_user_can( 'edit_posts' ) ) { |
|
| 78 | add_submenu_page( 'jetpack', __( 'Settings', 'jetpack' ), __( 'Settings', 'jetpack' ), 'jetpack_admin_page', 'jetpack#/settings', '__return_null' ); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | function add_fallback_head_meta() { |
||
| 83 | echo '<meta http-equiv="refresh" content="0; url=?page=jetpack_modules">'; |
||
| 84 | } |
||
| 85 | |||
| 86 | function add_noscript_head_meta() { |
||
| 87 | echo '<noscript>'; |
||
| 88 | $this->add_fallback_head_meta(); |
||
| 89 | echo '</noscript>'; |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Custom menu order. |
||
| 94 | * |
||
| 95 | * @deprecated since 9.2.0 |
||
| 96 | * @param array $menu_order Menu order. |
||
| 97 | * @return array |
||
| 98 | */ |
||
| 99 | function jetpack_menu_order( $menu_order ) { |
||
| 100 | _deprecated_function( __METHOD__, 'jetpack-9.2' ); |
||
| 101 | |||
| 102 | return $menu_order; |
||
| 103 | } |
||
| 104 | |||
| 105 | function page_render() { |
||
| 106 | /** This action is already documented in views/admin/admin-page.php */ |
||
| 107 | do_action( 'jetpack_notices' ); |
||
| 108 | |||
| 109 | // Try fetching by patch |
||
| 110 | $static_html = @file_get_contents( JETPACK__PLUGIN_DIR . '_inc/build/static.html' ); |
||
| 111 | |||
| 112 | if ( false === $static_html ) { |
||
| 113 | |||
| 114 | // If we still have nothing, display an error |
||
| 115 | echo '<p>'; |
||
| 116 | esc_html_e( 'Error fetching static.html. Try running: ', 'jetpack' ); |
||
| 117 | echo '<code>yarn distclean && yarn build</code>'; |
||
| 118 | echo '</p>'; |
||
| 119 | } else { |
||
| 120 | |||
| 121 | // We got the static.html so let's display it |
||
| 122 | echo $static_html; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Gets array of any Jetpack notices that have been dismissed. |
||
| 128 | * |
||
| 129 | * @since 4.0.1 |
||
| 130 | * @return mixed|void |
||
| 131 | */ |
||
| 132 | function get_dismissed_jetpack_notices() { |
||
| 133 | $jetpack_dismissed_notices = get_option( 'jetpack_dismissed_notices', array() ); |
||
| 134 | /** |
||
| 135 | * Array of notices that have been dismissed. |
||
| 136 | * |
||
| 137 | * @since 4.0.1 |
||
| 138 | * |
||
| 139 | * @param array $jetpack_dismissed_notices If empty, will not show any Jetpack notices. |
||
| 140 | */ |
||
| 141 | $dismissed_notices = apply_filters( 'jetpack_dismissed_notices', $jetpack_dismissed_notices ); |
||
| 142 | return $dismissed_notices; |
||
| 143 | } |
||
| 144 | |||
| 145 | function additional_styles() { |
||
| 146 | Jetpack_Admin_Page::load_wrapper_styles(); |
||
| 147 | } |
||
| 148 | |||
| 149 | function page_admin_scripts() { |
||
| 150 | if ( $this->is_redirecting ) { |
||
| 151 | return; // No need for scripts on a fallback page |
||
| 152 | } |
||
| 153 | |||
| 154 | $status = new Status(); |
||
| 155 | $is_offline_mode = $status->is_offline_mode(); |
||
| 156 | $site_suffix = $status->get_site_suffix(); |
||
| 157 | $script_deps_path = JETPACK__PLUGIN_DIR . '_inc/build/admin.asset.php'; |
||
| 158 | $script_dependencies = array( 'wp-polyfill' ); |
||
| 159 | if ( file_exists( $script_deps_path ) ) { |
||
| 160 | $asset_manifest = include $script_deps_path; |
||
| 161 | $script_dependencies = $asset_manifest['dependencies']; |
||
| 162 | } |
||
| 163 | |||
| 164 | wp_enqueue_script( |
||
| 165 | 'react-plugin', |
||
| 166 | plugins_url( '_inc/build/admin.js', JETPACK__PLUGIN_FILE ), |
||
| 167 | $script_dependencies, |
||
| 168 | JETPACK__VERSION, |
||
| 169 | true |
||
| 170 | ); |
||
| 171 | |||
| 172 | if ( ! $is_offline_mode && Jetpack::is_active() ) { |
||
| 173 | // Required for Analytics. |
||
| 174 | wp_enqueue_script( 'jp-tracks', '//stats.wp.com/w.js', array(), gmdate( 'YW' ), true ); |
||
| 175 | } |
||
| 176 | |||
| 177 | wp_set_script_translations( 'react-plugin', 'jetpack' ); |
||
| 178 | |||
| 179 | // Add objects to be passed to the initial state of the app. |
||
| 180 | // Use wp_add_inline_script instead of wp_localize_script, see https://core.trac.wordpress.org/ticket/25280. |
||
| 181 | wp_add_inline_script( 'react-plugin', 'var Initial_State=JSON.parse(decodeURIComponent("' . rawurlencode( wp_json_encode( $this->get_initial_state() ) ) . '"));', 'before' ); |
||
| 182 | |||
| 183 | // This will set the default URL of the jp_redirects lib. |
||
| 184 | wp_add_inline_script( 'react-plugin', 'var jetpack_redirects = { currentSiteRawUrl: "' . $site_suffix . '" };', 'before' ); |
||
| 185 | } |
||
| 186 | |||
| 187 | function get_initial_state() { |
||
| 188 | global $is_safari; |
||
| 189 | // Load API endpoint base classes and endpoints for getting the module list fed into the JS Admin Page |
||
| 190 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/class.jetpack-core-api-xmlrpc-consumer-endpoint.php'; |
||
| 191 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php'; |
||
| 192 | $moduleListEndpoint = new Jetpack_Core_API_Module_List_Endpoint(); |
||
| 193 | $modules = $moduleListEndpoint->get_modules(); |
||
| 194 | |||
| 195 | // Preparing translated fields for JSON encoding by transforming all HTML entities to |
||
| 196 | // respective characters. |
||
| 197 | foreach( $modules as $slug => $data ) { |
||
| 198 | $modules[ $slug ]['name'] = html_entity_decode( $data['name'] ); |
||
| 199 | $modules[ $slug ]['description'] = html_entity_decode( $data['description'] ); |
||
| 200 | $modules[ $slug ]['short_description'] = html_entity_decode( $data['short_description'] ); |
||
| 201 | $modules[ $slug ]['long_description'] = html_entity_decode( $data['long_description'] ); |
||
| 202 | } |
||
| 203 | |||
| 204 | // Collecting roles that can view site stats. |
||
| 205 | $stats_roles = array(); |
||
| 206 | $enabled_roles = function_exists( 'stats_get_option' ) ? stats_get_option( 'roles' ) : array( 'administrator' ); |
||
| 207 | |||
| 208 | if ( ! function_exists( 'get_editable_roles' ) ) { |
||
| 209 | require_once ABSPATH . 'wp-admin/includes/user.php'; |
||
| 210 | } |
||
| 211 | foreach ( get_editable_roles() as $slug => $role ) { |
||
| 212 | $stats_roles[ $slug ] = array( |
||
| 213 | 'name' => translate_user_role( $role['name'] ), |
||
| 214 | 'canView' => is_array( $enabled_roles ) ? in_array( $slug, $enabled_roles, true ) : false, |
||
| 215 | ); |
||
| 216 | } |
||
| 217 | |||
| 218 | // Get information about current theme. |
||
| 219 | $current_theme = wp_get_theme(); |
||
| 220 | |||
| 221 | // Get all themes that Infinite Scroll provides support for natively. |
||
| 222 | $inf_scr_support_themes = array(); |
||
| 223 | foreach ( Jetpack::glob_php( JETPACK__PLUGIN_DIR . 'modules/infinite-scroll/themes' ) as $path ) { |
||
| 224 | if ( is_readable( $path ) ) { |
||
| 225 | $inf_scr_support_themes[] = basename( $path, '.php' ); |
||
| 226 | } |
||
| 227 | } |
||
| 228 | |||
| 229 | // Get last post, to build the link to Customizer in the Related Posts module. |
||
| 230 | $last_post = get_posts( array( 'posts_per_page' => 1 ) ); |
||
| 231 | $last_post = isset( $last_post[0] ) && $last_post[0] instanceof WP_Post |
||
| 232 | ? get_permalink( $last_post[0]->ID ) |
||
| 233 | : get_home_url(); |
||
| 234 | |||
| 235 | $current_user_data = jetpack_current_user_data(); |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Adds information to the `connectionStatus` API field that is unique to the Jetpack React dashboard. |
||
| 239 | */ |
||
| 240 | $connection_status = array( |
||
| 241 | 'isInIdentityCrisis' => Jetpack::validate_sync_error_idc_option(), |
||
| 242 | 'sandboxDomain' => JETPACK__SANDBOX_DOMAIN, |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Filter to add connection errors |
||
| 246 | * Format: array( array( 'code' => '...', 'message' => '...', 'action' => '...' ), ... ) |
||
| 247 | * |
||
| 248 | * @since 8.7.0 |
||
| 249 | * |
||
| 250 | * @param array $errors Connection errors. |
||
| 251 | */ |
||
| 252 | 'errors' => apply_filters( 'react_connection_errors_initial_state', array() ), |
||
| 253 | ); |
||
| 254 | |||
| 255 | $connection_status = array_merge( REST_Connector::connection_status( false ), $connection_status ); |
||
| 256 | |||
| 257 | return array( |
||
| 258 | 'WP_API_root' => esc_url_raw( rest_url() ), |
||
| 259 | 'WP_API_nonce' => wp_create_nonce( 'wp_rest' ), |
||
| 260 | 'pluginBaseUrl' => plugins_url( '', JETPACK__PLUGIN_FILE ), |
||
| 261 | 'connectionStatus' => $connection_status, |
||
| 262 | 'connectUrl' => false == $current_user_data['isConnected'] // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
||
| 263 | ? Jetpack::init()->build_connect_url( true, false, false ) |
||
| 264 | : '', |
||
| 265 | 'dismissedNotices' => $this->get_dismissed_jetpack_notices(), |
||
| 266 | 'isDevVersion' => Jetpack::is_development_version(), |
||
| 267 | 'currentVersion' => JETPACK__VERSION, |
||
| 268 | 'is_gutenberg_available' => true, |
||
| 269 | 'getModules' => $modules, |
||
| 270 | 'rawUrl' => ( new Status() )->get_site_suffix(), |
||
| 271 | 'adminUrl' => esc_url( admin_url() ), |
||
| 272 | 'siteTitle' => (string) htmlspecialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), |
||
| 273 | 'stats' => array( |
||
| 274 | // data is populated asynchronously on page load. |
||
| 275 | 'data' => array( |
||
| 276 | 'general' => false, |
||
| 277 | 'day' => false, |
||
| 278 | 'week' => false, |
||
| 279 | 'month' => false, |
||
| 280 | ), |
||
| 281 | 'roles' => $stats_roles, |
||
| 282 | ), |
||
| 283 | 'aff' => Partner::init()->get_partner_code( Partner::AFFILIATE_CODE ), |
||
| 284 | 'partnerSubsidiaryId' => Partner::init()->get_partner_code( Partner::SUBSIDIARY_CODE ), |
||
| 285 | 'settings' => $this->get_flattened_settings( $modules ), |
||
| 286 | 'userData' => array( |
||
| 287 | 'currentUser' => $current_user_data, |
||
| 288 | ), |
||
| 289 | 'siteData' => array( |
||
| 290 | 'icon' => has_site_icon() |
||
| 291 | ? apply_filters( 'jetpack_photon_url', get_site_icon_url(), array( 'w' => 64 ) ) |
||
| 292 | : '', |
||
| 293 | 'siteVisibleToSearchEngines' => '1' == get_option( 'blog_public' ), // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
||
| 294 | /** |
||
| 295 | * Whether promotions are visible or not. |
||
| 296 | * |
||
| 297 | * @since 4.8.0 |
||
| 298 | * |
||
| 299 | * @param bool $are_promotions_active Status of promotions visibility. True by default. |
||
| 300 | */ |
||
| 301 | 'showPromotions' => apply_filters( 'jetpack_show_promotions', true ), |
||
| 302 | 'isAtomicSite' => jetpack_is_atomic_site(), |
||
| 303 | 'plan' => Jetpack_Plan::get(), |
||
| 304 | 'showBackups' => Jetpack::show_backups_ui(), |
||
| 305 | 'showSetupWizard' => $this->show_setup_wizard(), |
||
| 306 | 'isMultisite' => is_multisite(), |
||
| 307 | 'dateFormat' => get_option( 'date_format' ), |
||
| 308 | ), |
||
| 309 | 'themeData' => array( |
||
| 310 | 'name' => $current_theme->get( 'Name' ), |
||
| 311 | 'hasUpdate' => (bool) get_theme_update_available( $current_theme ), |
||
| 312 | 'support' => array( |
||
| 313 | 'infinite-scroll' => current_theme_supports( 'infinite-scroll' ) || in_array( $current_theme->get_stylesheet(), $inf_scr_support_themes, true ), |
||
| 314 | ), |
||
| 315 | ), |
||
| 316 | 'jetpackStateNotices' => array( |
||
| 317 | 'messageCode' => Jetpack::state( 'message' ), |
||
| 318 | 'errorCode' => Jetpack::state( 'error' ), |
||
| 319 | 'errorDescription' => Jetpack::state( 'error_description' ), |
||
| 320 | 'messageContent' => Jetpack::state( 'display_update_modal' ) ? $this->get_update_modal_data() : null, |
||
| 321 | ), |
||
| 322 | 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(), |
||
| 323 | 'currentIp' => function_exists( 'jetpack_protect_get_ip' ) ? jetpack_protect_get_ip() : false, |
||
| 324 | 'lastPostUrl' => esc_url( $last_post ), |
||
| 325 | 'externalServicesConnectUrls' => $this->get_external_services_connect_urls(), |
||
| 326 | 'calypsoEnv' => Jetpack::get_calypso_env(), |
||
| 327 | 'products' => Jetpack::get_products_for_purchase(), |
||
| 328 | 'setupWizardStatus' => Jetpack_Options::get_option( 'setup_wizard_status', 'not-started' ), |
||
| 329 | 'isSafari' => $is_safari, |
||
| 330 | 'doNotUseConnectionIframe' => Constants::is_true( 'JETPACK_SHOULD_NOT_USE_CONNECTION_IFRAME' ), |
||
| 331 | 'licensing' => array( |
||
| 332 | 'error' => Licensing::instance()->last_error(), |
||
| 333 | ), |
||
| 334 | ); |
||
| 335 | } |
||
| 336 | |||
| 337 | function get_external_services_connect_urls() { |
||
| 338 | $connect_urls = array(); |
||
| 339 | jetpack_require_lib( 'class.jetpack-keyring-service-helper' ); |
||
| 340 | foreach ( Jetpack_Keyring_Service_Helper::$SERVICES as $service_name => $service_info ) { |
||
| 341 | $connect_urls[ $service_name ] = Jetpack_Keyring_Service_Helper::connect_url( $service_name, $service_info[ 'for' ] ); |
||
| 342 | } |
||
| 343 | return $connect_urls; |
||
| 344 | } |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Returns an array of modules and settings both as first class members of the object. |
||
| 348 | * |
||
| 349 | * @param array $modules the result of an API request to get all modules. |
||
| 350 | * |
||
| 351 | * @return array flattened settings with modules. |
||
| 352 | */ |
||
| 353 | function get_flattened_settings( $modules ) { |
||
| 354 | $core_api_endpoint = new Jetpack_Core_API_Data(); |
||
| 355 | $settings = $core_api_endpoint->get_all_options(); |
||
| 356 | return $settings->data; |
||
| 357 | } |
||
| 358 | |||
| 359 | |||
| 360 | /** |
||
| 361 | * Returns a boolean for whether the Setup Wizard should be displayed or not. |
||
| 362 | * |
||
| 363 | * @return bool True if the Setup Wizard should be displayed, false otherwise. |
||
| 364 | */ |
||
| 365 | public function show_setup_wizard() { |
||
| 366 | return Jetpack_Wizard::can_be_displayed(); |
||
| 367 | } |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Returns the release post content and image data as an associative array. |
||
| 371 | * This data is used to create the update modal. |
||
| 372 | */ |
||
| 373 | public function get_update_modal_data() { |
||
| 374 | $post_data = $this->get_release_post_data(); |
||
| 375 | |||
| 376 | if ( ! isset( $post_data['posts'][0] ) ) { |
||
| 377 | return; |
||
| 378 | } |
||
| 379 | |||
| 380 | $post = $post_data['posts'][0]; |
||
| 381 | |||
| 382 | if ( empty( $post['content'] ) ) { |
||
| 383 | return; |
||
| 384 | } |
||
| 385 | |||
| 386 | // This allows us to embed videopress videos into the release post. |
||
| 387 | add_filter( 'wp_kses_allowed_html', array( $this, 'allow_post_embed_iframe' ), 10, 2 ); |
||
| 388 | $content = wp_kses_post( $post['content'] ); |
||
| 389 | remove_filter( 'wp_kses_allowed_html', array( $this, 'allow_post_embed_iframe' ), 10, 2 ); |
||
|
0 ignored issues
–
show
|
|||
| 390 | |||
| 391 | $post_title = isset( $post['title'] ) ? $post['title'] : null; |
||
| 392 | $title = wp_kses( $post_title, array() ); |
||
| 393 | |||
| 394 | $post_thumbnail = isset( $post['post_thumbnail'] ) ? $post['post_thumbnail'] : null; |
||
| 395 | if ( ! empty( $post_thumbnail ) ) { |
||
| 396 | jetpack_require_lib( 'class.jetpack-photon-image' ); |
||
| 397 | $photon_image = new Jetpack_Photon_Image( |
||
| 398 | array( |
||
| 399 | 'file' => jetpack_photon_url( $post_thumbnail['URL'] ), |
||
| 400 | 'width' => $post_thumbnail['width'], |
||
| 401 | 'height' => $post_thumbnail['height'], |
||
| 402 | ), |
||
| 403 | $post_thumbnail['mime_type'] |
||
| 404 | ); |
||
| 405 | $photon_image->resize( |
||
| 406 | array( |
||
| 407 | 'width' => 600, |
||
| 408 | 'height' => null, |
||
| 409 | 'crop' => false, |
||
| 410 | ) |
||
| 411 | ); |
||
| 412 | $post_thumbnail_url = $photon_image->get_raw_filename(); |
||
| 413 | } else { |
||
| 414 | $post_thumbnail_url = null; |
||
| 415 | } |
||
| 416 | |||
| 417 | $post_array = array( |
||
| 418 | 'release_post_content' => $content, |
||
| 419 | 'release_post_featured_image' => $post_thumbnail_url, |
||
| 420 | 'release_post_title' => $title, |
||
| 421 | ); |
||
| 422 | |||
| 423 | return $post_array; |
||
| 424 | } |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Temporarily allow post content to contain iframes, e.g. for videopress. |
||
| 428 | * |
||
| 429 | * @param string $tags The tags. |
||
| 430 | * @param string $context The context. |
||
| 431 | */ |
||
| 432 | public function allow_post_embed_iframe( $tags, $context ) { |
||
| 433 | if ( 'post' === $context ) { |
||
| 434 | $tags['iframe'] = array( |
||
| 435 | 'src' => true, |
||
| 436 | 'height' => true, |
||
| 437 | 'width' => true, |
||
| 438 | 'frameborder' => true, |
||
| 439 | 'allowfullscreen' => true, |
||
| 440 | ); |
||
| 441 | } |
||
| 442 | |||
| 443 | return $tags; |
||
| 444 | } |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Obtains the release post from the Jetpack release post blog. A release post will be displayed in the |
||
| 448 | * update modal when a post has a tag equal to the Jetpack version number. |
||
| 449 | * |
||
| 450 | * The response parameters for the post array can be found here: |
||
| 451 | * https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/posts/%24post_ID/#apidoc-response |
||
| 452 | * |
||
| 453 | * @return array|null Returns an associative array containing the release post data at index ['posts'][0]. |
||
| 454 | * Returns null if the release post data is not available. |
||
| 455 | */ |
||
| 456 | private function get_release_post_data() { |
||
| 457 | if ( Constants::is_defined( 'TESTING_IN_JETPACK' ) && Constants::get_constant( 'TESTING_IN_JETPACK' ) ) { |
||
| 458 | return null; |
||
| 459 | } |
||
| 460 | |||
| 461 | $release_post_src = add_query_arg( |
||
| 462 | array( |
||
| 463 | 'order_by' => 'date', |
||
| 464 | 'tag' => JETPACK__VERSION, |
||
| 465 | 'number' => '1', |
||
| 466 | ), |
||
| 467 | 'https://public-api.wordpress.com/rest/v1/sites/' . JETPACK__RELEASE_POST_BLOG_SLUG . '/posts' |
||
| 468 | ); |
||
| 469 | |||
| 470 | $response = wp_remote_get( $release_post_src ); |
||
| 471 | |||
| 472 | if ( ! is_array( $response ) ) { |
||
| 473 | return null; |
||
| 474 | } |
||
| 475 | |||
| 476 | return json_decode( wp_remote_retrieve_body( $response ), true ); |
||
| 477 | } |
||
| 478 | } |
||
| 479 | |||
| 480 | /** |
||
| 481 | * Gather data about the current user. |
||
| 482 | * |
||
| 483 | * @since 4.1.0 |
||
| 484 | * |
||
| 485 | * @return array |
||
| 486 | */ |
||
| 487 | function jetpack_current_user_data() { |
||
| 488 | $current_user = wp_get_current_user(); |
||
| 489 | $is_master_user = $current_user->ID == Jetpack_Options::get_option( 'master_user' ); |
||
| 490 | $dotcom_data = Jetpack::get_connected_user_data(); |
||
| 491 | |||
| 492 | // Add connected user gravatar to the returned dotcom_data. |
||
| 493 | $dotcom_data['avatar'] = ( ! empty( $dotcom_data['email'] ) ? |
||
| 494 | get_avatar_url( |
||
| 495 | $dotcom_data['email'], |
||
| 496 | array( |
||
| 497 | 'size' => 64, |
||
| 498 | 'default' => 'mysteryman', |
||
| 499 | ) |
||
| 500 | ) |
||
| 501 | : false ); |
||
| 502 | |||
| 503 | $current_user_data = array( |
||
| 504 | 'isConnected' => Jetpack::is_user_connected( $current_user->ID ), |
||
| 505 | 'isMaster' => $is_master_user, |
||
| 506 | 'username' => $current_user->user_login, |
||
| 507 | 'id' => $current_user->ID, |
||
| 508 | 'wpcomUser' => $dotcom_data, |
||
| 509 | 'gravatar' => get_avatar_url( $current_user->ID, 64, 'mm', '', array( 'force_display' => true ) ), |
||
| 510 | 'permissions' => array( |
||
| 511 | 'admin_page' => current_user_can( 'jetpack_admin_page' ), |
||
| 512 | 'connect' => current_user_can( 'jetpack_connect' ), |
||
| 513 | 'disconnect' => current_user_can( 'jetpack_disconnect' ), |
||
| 514 | 'manage_modules' => current_user_can( 'jetpack_manage_modules' ), |
||
| 515 | 'network_admin' => current_user_can( 'jetpack_network_admin_page' ), |
||
| 516 | 'network_sites_page' => current_user_can( 'jetpack_network_sites_page' ), |
||
| 517 | 'edit_posts' => current_user_can( 'edit_posts' ), |
||
| 518 | 'publish_posts' => current_user_can( 'publish_posts' ), |
||
| 519 | 'manage_options' => current_user_can( 'manage_options' ), |
||
| 520 | 'view_stats' => current_user_can( 'view_stats' ), |
||
| 521 | 'manage_plugins' => current_user_can( 'install_plugins' ) |
||
| 522 | && current_user_can( 'activate_plugins' ) |
||
| 523 | && current_user_can( 'update_plugins' ) |
||
| 524 | && current_user_can( 'delete_plugins' ), |
||
| 525 | ), |
||
| 526 | ); |
||
| 527 | |||
| 528 | return $current_user_data; |
||
| 529 | } |
||
| 530 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.