'jetpackNewsletterWidgetConfigData', 'config_data' => static::get_config_data(), ) ); $widget_title = sprintf( __( 'Newsletter', 'jetpack' ) ); wp_add_dashboard_widget( self::$widget_id, $widget_title, array( static::class, 'render' ), // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. null, array(), 'side', 'high' ); } } /** * Render the Jetpack Newsletter widget. * * @return void */ public static function render() { ?>
'jetpackNewsletterWidgetConfigData', 'config_data' => static::get_config_data(), ) ); } /** * Load the admin scripts for the Jetpack Newsletter widget. * * @param string $asset_handle The handle of the asset. * @param string $asset_name The name of the asset. * @param array $options The options for the asset. * @return void */ public static function load_admin_scripts( $asset_handle, $asset_name, $options = array() ) { $default_options = array( 'config_data' => array(), 'config_variable_name' => 'configData', 'enqueue_css' => true, ); $options = wp_parse_args( $options, $default_options ); // Get the asset file path $asset_path = JETPACK__PLUGIN_DIR . '_inc/build/' . $asset_name . '.min.asset.php'; // Get dependencies and version from asset file $dependencies = array(); $version = JETPACK__VERSION; if ( file_exists( $asset_path ) ) { $asset = require $asset_path; $dependencies = $asset['dependencies']; $version = $asset['version']; } // Register and enqueue the script wp_register_script( $asset_handle, plugins_url( '_inc/build/' . $asset_name . '.min.js', JETPACK__PLUGIN_FILE ), $dependencies, $version, true ); wp_enqueue_script( $asset_handle ); // Enqueue the CSS if enabled if ( $options['enqueue_css'] ) { wp_enqueue_style( $asset_handle, plugins_url( '_inc/build/' . $asset_name . '.css', JETPACK__PLUGIN_FILE ), array(), $version ); // Enqueue RTL stylesheet if needed if ( is_rtl() ) { wp_enqueue_style( $asset_handle . '-rtl', plugins_url( '_inc/build/' . $asset_name . '.rtl.css', JETPACK__PLUGIN_FILE ), array( $asset_handle ), $version ); } } // Add any configuration data if needed if ( ! empty( $options['config_data'] ) ) { wp_add_inline_script( $asset_handle, "window.{$options['config_variable_name']} = " . wp_json_encode( $options['config_data'] ) . ';', 'before' ); } } }