n_compare( $prev_version, '2.9.5', '<=' ) ) { $network_cap = apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' ); foreach ( get_super_admins() as $admin ) { $user = new WP_User( 0, $admin ); $user->remove_cap( $network_cap ); } } clean_snippets_cache( $table_name ); } /** * Migrate data from the old integer method of storing scopes to the new string method * * @param string $table_name Name of database table. */ private function migrate_scope_data( string $table_name ) { global $wpdb; $scopes = array( 0 => 'global', 1 => 'admin', 2 => 'front-end', ); foreach ( $scopes as $scope_number => $scope_name ) { // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching, will flush at end of process. $wpdb->query( $wpdb->prepare( "UPDATE $table_name SET scope = %s WHERE scope = %d", $scope_name, $scope_number ) ); } } /** * Build a collection of sample snippets for new users to try out. * * @return Snippet[] List of Snippet objects. */ private function get_sample_content(): array { $tag = "\n\n" . esc_html__( 'This is a sample snippet. Feel free to use it, edit it, or remove it.', 'code-snippets' ); $snippets_data = array( array( 'name' => esc_html__( 'Make upload filenames lowercase', 'code-snippets' ), 'code' => "add_filter( 'sanitize_file_name', 'mb_strtolower' );", 'desc' => esc_html__( 'Makes sure that image and file uploads have lowercase filenames.', 'code-snippets' ) . $tag, 'tags' => array( 'sample', 'media' ), ), array( 'name' => esc_html__( 'Disable admin bar', 'code-snippets' ), 'code' => "add_action( 'wp', function () {\n\tif ( ! current_user_can( 'manage_options' ) ) {\n\t\tshow_admin_bar( false );\n\t}\n} );", 'desc' => esc_html__( 'Turns off the WordPress admin bar for everyone except administrators.', 'code-snippets' ) . $tag, 'tags' => array( 'sample', 'admin-bar' ), 'scope' => 'front-end', ), array( 'name' => esc_html__( 'Allow smilies', 'code-snippets' ), 'code' => "add_filter( 'widget_text', 'convert_smilies' );\nadd_filter( 'the_title', 'convert_smilies' );\nadd_filter( 'wp_title', 'convert_smilies' );\nadd_filter( 'get_bloginfo', 'convert_smilies' );", 'desc' => esc_html__( 'Allows smiley conversion in obscure places.', 'code-snippets' ) . $tag, 'tags' => array( 'sample' ), ), array( 'name' => esc_html__( 'Current year', 'code-snippets' ), 'code' => "2026", 'desc' => esc_html__( 'Shortcode for inserting the current year into a post or page..', 'code-snippets' ) . $tag, 'tags' => array( 'sample', 'dates' ), 'scope' => 'content', ), ); return array_map( function ( $snippet_data ) { return new Snippet( $snippet_data ); }, $snippets_data ); } }