here semi auto updates should work (Admin panel notice and install on confirmation). If not please manually update as described here.', 'advanced-responsive-video-embedder' ), $name, $req_ver, esc_url( get_admin_url() . 'options-general.php?page=nextgenthemes' ), 'https://nextgenthemes.com/plugins/arve/documentation/installation/' ); Notices::instance()->register_notice( 'ngt-arve-' . $name . '-outdated-v' . $req_ver, 'notice-error', wp_kses( $msg, ALLOWED_HTML, array( 'https' ) ), array( 'cap' => 'update_plugins', ) ); } } function action_admin_init_setup_messages(): void { foreach ( ADDONS as $addon_name ) { addon_outdated_notice( $addon_name ); } if ( display_pro_ad() ) { Notices::instance()->register_notice( 'ngt-arve-addon-ad', 'notice-info', wp_kses( ad_html(), ALLOWED_HTML, array( 'https' ) ), array( 'cap' => 'install_plugins', ) ); } if ( str_contains_any( VERSION, array( 'alpha', 'beta' ) ) && version_compare( VERSION, get_latest_beta(), '<' ) ) { $beta_ver = get_latest_beta(); Notices::instance()->register_notice( "ngt-arve-beta-$beta_ver", 'notice-info', wp_kses( sprintf( // Translators: %1$s URL, %2$s version tag. __( 'Latest ARVE pre-release is out! Please do a manual update.
(1) Download arve-%2$s.zip. (2) Go to Plugins > Add New > Upload Plugin. (3) Install. (4) nextgenthemes.com/support/ if something goes wrong.', 'advanced-responsive-video-embedder' ), esc_url( "https://github.com/nextgenthemes/advanced-responsive-video-embedder/releases/download/$beta_ver/advanced-responsive-video-embedder-$beta_ver.zip" ), esc_html( $beta_ver ), esc_url( 'https://nextgenthemes.com/support/' ) ), ALLOWED_HTML, array( 'https' ) ), array( 'cap' => 'install_plugins', ) ); } if ( is_gutenberg() && ! is_plugin_active( 'gutenberg/gutenberg.php' ) && version_compare( $GLOBALS['wp_version'], '6.6-beta2', '<' ) ) { Notices::instance()->register_notice( 'ngt-arve-need-gb2', 'notice-info', wp_kses( sprintf( // Translators: %1$s URL, %2$s version tag. __( 'For the ARVE Block to work you currently need the Gutenberg plugin active or WP 6.6-RC2 or later. Reason is unknown at the time of writing this.', 'advanced-responsive-video-embedder' ), admin_url( 'plugin-install.php?s=Gutenberg%2520Team&tab=search&type=term' ), esc_url( 'https://wordpress.org/news/2024/07/wordpress-6-6-rc2/' ) ), ALLOWED_HTML, array( 'https' ) ), array( 'cap' => 'install_plugins', ) ); } } function get_latest_beta(): string { $ver = '10.0.0-alpha9'; $gh_tag = remote_get_json_cached( 'https://api.github.com/repos/nextgenthemes/advanced-responsive-video-embedder/releases/latest', array(), 'tag_name', HOUR_IN_SECONDS ); if ( ! is_wp_error( $gh_tag ) && str_contains_any( $gh_tag, array( 'alpha', 'beta' ) ) ) { $ver = $gh_tag; } return $ver; } function ad_html(): string { $html = esc_html__( 'Hi, this is Nico(las Jonas) the author of the ARVE Advanced Responsive Video Embedder plugin. If you are interested in additional features and/or want to support the work I do on this plugin please consider buying the Pro Addon.', 'advanced-responsive-video-embedder' ); $html = "

$html

'; return $html; } function display_pro_ad(): bool { $inst = (int) get_option( 'arve_install_date' ); if ( get_user_meta( get_current_user_id(), 'arve_dismiss_pro_notice', false ) || is_plugin_active( 'arve-pro/arve-pro.php' ) || time() < strtotime( '+3 weeks', $inst ) ) { return false; } return true; } function widget_text(): void { echo '

'; printf( 'Documentation, ', 'https://nextgenthemes.com/plugins/arve/documentation/' ); printf( 'Support, ', 'https://nextgenthemes.com/support/' ); printf( '%s', esc_url( admin_url( 'admin.php?page=advanced-responsive-video-embedder' ) ), esc_html__( 'Settings', 'advanced-responsive-video-embedder' ) ); echo '

'; printf( 'ARVE Pro Addon Features:', 'https://nextgenthemes.com/plugins/arve-pro/' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_readfile echo wp_kses( ad_html(), ALLOWED_HTML, array( 'https' ) ); } function register_shortcode_ui(): void { $attrs = array(); $settings = settings( 'shortcode' )->get_all(); foreach ( $settings as $key => $s ) : $field = array( 'attr' => $key, 'label' => $s->label, ); if ( ! empty( $s->placeholder ) ) { $field['meta']['placeholder'] = $s->placeholder; } if ( 'thumbnail' === $key ) { $field['type'] = 'attachment'; $field['libraryType'] = array( 'image' ); $field['addButton'] = __( 'Select Image', 'advanced-responsive-video-embedder' ); $field['frameTitle'] = __( 'Select Image', 'advanced-responsive-video-embedder' ); } switch ( $s->type ) { case 'boolean': $field['type'] = 'checkbox'; break; case 'string': if ( $s->options ) { $field['type'] = 'select'; $field['options'] = convert_to_shortcode_ui_options( $s->options ); } else { $field['type'] = 'text'; } break; case 'integer': $field['type'] = 'number'; break; } $attrs[] = $field; endforeach; \shortcode_ui_register_for_shortcode( 'arve', array( 'label' => esc_html( 'ARVE' ), 'listItemImage' => 'dashicons-format-video', 'attrs' => $attrs, ) ); } /** * Converts an associative array to an array of options suitable for Shortcode UI. * Each key-value pair in the input array is transformed into an associative array * with 'value' and 'label' keys. * * @param array $arr An associative array with keys as option values and values as option labels. * * @return array> An array of associative arrays, each containing 'value' and 'label' keys. */ function convert_to_shortcode_ui_options( array $arr ): array { $result = array(); foreach ( $arr as $key => $value ) { $result[] = array( 'value' => $key, 'label' => $value, ); } return $result; } function add_dashboard_widget(): void { if ( ! display_pro_ad() ) { return; } wp_add_dashboard_widget( 'arve_dashboard_widget', // Widget slug. 'Advanced Responsive Video Embedder', // Title. __NAMESPACE__ . '\widget_text' // Display function. ); if ( 'index.php' === $GLOBALS['pagenow'] ) { // Get the regular dashboard widgets array. // (which has our new widget already but at the end). $normal_dashboard = $GLOBALS['wp_meta_boxes']['dashboard']['normal']['core']; // Backup and delete our new dashboard widget from the end of the array. $arve_widget_backup = array( 'arve_dashboard_widget' => $normal_dashboard['arve_dashboard_widget'] ); unset( $normal_dashboard['arve_dashboard_widget'] ); // Merge the two arrays together so our widget is at the beginning. $sorted_dashboard = array_merge( $arve_widget_backup, $normal_dashboard ); // Save the sorted array back into the original metaboxes. // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited $GLOBALS['wp_meta_boxes']['dashboard']['normal']['core'] = $sorted_dashboard; } } /** * @param array $links Array containing link html as values. * @return array Updated Array containing link html as values. */ function add_action_links( array $links ): array { if ( ! is_plugin_active( 'arve-pro/arve-pro.php' ) ) { $links['buy_pro_addon'] = sprintf( '%s', 'https://nextgenthemes.com/plugins/arve-pro/', __( 'Get Lazyload, Lightbox and more', 'advanced-responsive-video-embedder' ) ); } return $links; } function admin_enqueue_styles(): void { // This shit prevents 'arve-admin-css was added to the iframe incorrectly.' error but it doesn't work with enqueue_block_editor_assets // if ( did_action( 'wp_enqueue_editor' ) ) { return; } wp_enqueue_style( 'arve-admin', plugins_url( 'build/admin.css', PLUGIN_FILE ), array( 'nextgenthemes-settings' ), ver( PLUGIN_DIR . '/build/admin.css', VERSION ), ); } function get_first_glob( string $pattern ): string { $res = glob( $pattern, GLOB_NOSORT | GLOB_ERR ); if ( empty( $res[0] ) ) { return ''; } return $res[0]; } function admin_enqueue_scripts(): void { wp_enqueue_script_module( 'arve-admin', plugins_url( 'build/admin.js', PLUGIN_FILE ), array(), ver( PLUGIN_DIR . '/build/admin.js', VERSION ) ); if ( is_plugin_active( 'shortcode-ui/shortcode-ui.php' ) ) { wp_enqueue_script( 'arve-admin-sc-ui', plugins_url( 'build/shortcode-ui.js', PLUGIN_FILE ), array( 'shortcode-ui' ), ver( PLUGIN_DIR . '/build/shortcode-ui.js', VERSION ), array( 'strategy' => 'defer' ), ); } } function action_admin_bar_menu( \WP_Admin_Bar $admin_bar ): void { if ( current_user_can( 'manage_options' ) && options()['admin_bar_menu'] ) { $admin_bar->add_menu( array( 'id' => 'arve-settings', 'title' => 'ARVE', 'href' => get_admin_url() . 'options-general.php?page=nextgenthemes_arve', 'meta' => array( 'title' => __( 'Advanced Responsive Video Embedder Settings', 'advanced-responsive-video-embedder' ) ), ) ); } }