get_plugins example

<?php     foreach ( $importers as $importer_id => $data ) {
        $plugin_slug         = '';
        $action              = '';
        $is_plugin_installed = false;

        if ( isset( $data['install'] ) ) {
            $plugin_slug = $data['install'];

            if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) {
                // Looks like an importer is installed, but not active.                 $plugins = get_plugins( '/' . $plugin_slug );
                if ( ! empty( $plugins ) ) {
                    $keys        = array_keys( $plugins );
                    $plugin_file = $plugin_slug . '/' . $keys[0];
                    $url         = wp_nonce_url(
                        add_query_arg(
                            array(
                                'action' => 'activate',
                                'plugin' => $plugin_file,
                                'from'   => 'import',
                            ),
                            admin_url( 'plugins.php' )
                        ),

    private function do_overwrite() {
        if ( 'upload' !== $this->type || ! is_wp_error( $this->result ) || 'folder_exists' !== $this->result->get_error_code() ) {
            return false;
        }

        $folder = $this->result->get_error_data( 'folder_exists' );
        $folder = ltrim( substr( $folderstrlen( WP_PLUGIN_DIR ) ), '/' );

        $current_plugin_data = false;
        $all_plugins         = get_plugins();

        foreach ( $all_plugins as $plugin => $plugin_data ) {
            if ( strrpos( $plugin$folder ) !== 0 ) {
                continue;
            }

            $current_plugin_data = $plugin_data;
        }

        $new_plugin_data = $this->upgrader->new_plugin_data;

        
global $pagenow;

    if ( ! in_array( $pagenow, array( 'link-manager.php', 'link-add.php', 'link.php' ), true ) ) {
        return;
    }

    add_filter( 'pre_option_link_manager_enabled', '__return_true', 100 );
    $really_can_manage_links = current_user_can( 'manage_links' );
    remove_filter( 'pre_option_link_manager_enabled', '__return_true', 100 );

    if ( $really_can_manage_links ) {
        $plugins = get_plugins();

        if ( empty( $plugins['link-manager/link-manager.php'] ) ) {
            if ( current_user_can( 'install_plugins' ) ) {
                $install_url = wp_nonce_url(
                    self_admin_url( 'update.php?action=install-plugin&plugin=link-manager' ),
                    'install-plugin_link-manager'
                );

                wp_die(
                    sprintf(
                        /* translators: %s: A link to install the Link Manager plugin. */
                        
/** * Finds an installed plugin for the given slug. * * @since 5.5.0 * * @param string $slug The WordPress.org directory slug for a plugin. * @return string The plugin file found matching it. */
    protected function find_plugin_for_slug( $slug ) {
        require_once ABSPATH . 'wp-admin/includes/plugin.php';

        $plugin_files = get_plugins( '/' . $slug );

        if ( ! $plugin_files ) {
            return '';
        }

        $plugin_files = array_keys( $plugin_files );

        return $slug . '/' . reset( $plugin_files );
    }

    /** * Retrieves the theme's schema, conforming to JSON Schema. * * @since 5.5.0 * * @return array Item schema data. */

    public function plugin_info() {
        if ( ! is_array( $this->result ) ) {
            return false;
        }
        if ( empty( $this->result['destination_name'] ) ) {
            return false;
        }

        // Ensure to pass with leading slash.         $plugin = get_plugins( '/' . $this->result['destination_name'] );
        if ( empty( $plugin ) ) {
            return false;
        }

        // Assume the requested plugin is the first in the list.         $pluginfiles = array_keys( $plugin );

        return $this->result['destination_name'] . '/' . $pluginfiles[0];
    }

    /** * Deactivates a plugin before it is upgraded. * * Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade(). * * @since 2.8.0 * @since 4.1.0 Added a return value. * * @param bool|WP_Error $response The installation response before the installation has started. * @param array $plugin Plugin package arguments. * @return bool|WP_Error The original `$response` parameter or WP_Error. */
if ( '.' === $plugin_slug ) {
                        $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
                        if ( $data ) {
                            $plugin_info[ $plugin ]                     = $data;
                            $plugin_info[ $plugin ]['is_uninstallable'] = is_uninstallable_plugin( $plugin );
                            if ( ! $plugin_info[ $plugin ]['Network'] ) {
                                $have_non_network_plugins = true;
                            }
                        }
                    } else {
                        // Get plugins list from that folder.                         $folder_plugins = get_plugins( '/' . $plugin_slug );
                        if ( $folder_plugins ) {
                            foreach ( $folder_plugins as $plugin_file => $data ) {
                                $plugin_info[ $plugin_file ]                     = _get_plugin_data_markup_translate( $plugin_file$data );
                                $plugin_info[ $plugin_file ]['is_uninstallable'] = is_uninstallable_plugin( $plugin );
                                if ( ! $plugin_info[ $plugin_file ]['Network'] ) {
                                    $have_non_network_plugins = true;
                                }
                            }
                        }
                    }
                }

                

    public function get_items( $request ) {
        require_once ABSPATH . 'wp-admin/includes/plugin.php';

        $plugins = array();

        foreach ( get_plugins() as $file => $data ) {
            if ( is_wp_error( $this->check_read_permission( $file ) ) ) {
                continue;
            }

            $data['_file'] = $file;

            if ( ! $this->does_plugin_match_request( $request$data ) ) {
                continue;
            }

            $plugins[] = $this->prepare_response_for_collection( $this->prepare_item_for_response( $data$request ) );
        }
if ( ! empty( $args['plugin'] ) ) {
        $plugin = $args['plugin'];

        if ( ! current_user_can( 'edit_plugins' ) ) {
            return new WP_Error( 'unauthorized', __( 'Sorry, you are not allowed to edit plugins for this site.' ) );
        }

        if ( ! wp_verify_nonce( $args['nonce'], 'edit-plugin_' . $file ) ) {
            return new WP_Error( 'nonce_failure' );
        }

        if ( ! array_key_exists( $pluginget_plugins() ) ) {
            return new WP_Error( 'invalid_plugin' );
        }

        if ( 0 !== validate_file( $fileget_plugin_files( $plugin ) ) ) {
            return new WP_Error( 'bad_plugin_file_path', __( 'Sorry, that file cannot be edited.' ) );
        }

        $editable_extensions = wp_get_plugin_file_editable_extensions( $plugin );

        $real_file = WP_PLUGIN_DIR . '/' . $file;

        

function do_block_editor_incompatible_meta_box( $data_object$box ) {
    $plugin  = _get_plugin_from_callback( $box['old_callback'] );
    $plugins = get_plugins();
    echo '<p>';
    if ( $plugin ) {
        /* translators: %s: The name of the plugin that generated this meta box. */
        printf( __( 'This meta box, from the %s plugin, is not compatible with the block editor.' ), "<strong>{$plugin['Name']}</strong>" );
    } else {
        _e( 'This meta box is not compatible with the block editor.' );
    }
    echo '</p>';

    if ( empty( $plugins['classic-editor/classic-editor.php'] ) ) {
        if ( current_user_can( 'install_plugins' ) ) {
            

function wp_dashboard_plugins_output( $rss$args = array() ) {
    _deprecated_function( __FUNCTION__, '4.8.0' );

    // Plugin feeds plus link to install them.     $popular = fetch_feed( $args['url']['popular'] );

    if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
        $plugin_slugs = array_keys( get_plugins() );
        set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS );
    }

    echo '<ul>';

    foreach ( array( $popular ) as $feed ) {
        if ( is_wp_error( $feed ) || ! $feed->get_item_quantity() )
            continue;

        $items = $feed->get_items(0, 5);

        
$version     = $plugin->new_version;
                if ( current_user_can( 'update_plugins' ) ) {
                    $url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . $update_file ), 'upgrade-plugin_' . $update_file );
                }
                break;
            }
        }
    }

    if ( 'install' === $status ) {
        if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) {
            $installed_plugin = get_plugins( '/' . $api->slug );
            if ( empty( $installed_plugin ) ) {
                if ( current_user_can( 'install_plugins' ) ) {
                    $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug );
                }
            } else {
                $key = array_keys( $installed_plugin );
                /* * Use the first plugin regardless of the name. * Could have issues for multiple plugins in one directory if they share different version numbers. */
                $key = reset( $key );

                
switch ( $update->type ) {
            case 'core':
                return 'WordPress'; // Not translated.
            case 'theme':
                $theme = wp_get_theme( $update->slug );
                if ( $theme->exists() ) {
                    return $theme->Get( 'Name' );
                }
                break;
            case 'plugin':
                $plugin_data = get_plugins( '/' . $update->slug );
                $plugin_data = reset( $plugin_data );
                if ( $plugin_data ) {
                    return $plugin_data['Name'];
                }
                break;
        }
        return '';
    }

    /** * Clears existing translations where this item is going to be installed into. * * @since 5.1.0 * * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. * * @param string $remote_destination The location on the remote filesystem to be cleared. * @return bool|WP_Error True upon success, WP_Error on failure. */

            }

            $info['wp-mu-plugins']['fields'][ sanitize_text_field( $plugin['Name'] ) ] = array(
                'label' => $plugin['Name'],
                'value' => $plugin_version_string,
                'debug' => $plugin_version_string_debug,
            );
        }

        // List all available plugins.         $plugins        = get_plugins();
        $plugin_updates = get_plugin_updates();
        $transient      = get_site_transient( 'update_plugins' );

        $auto_updates = array();

        $auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'plugin' );

        if ( $auto_updates_enabled ) {
            $auto_updates = (array) get_site_option( 'auto_update_plugins', array() );
        }

        

        if ( true === $result[ $plugin ] ) {
            $status['errorMessage'] = $upgrader->strings['up_to_date'];
            wp_send_json_error( $status );
        }

        $plugin_data = get_plugins( '/' . $result[ $plugin ]['destination_name'] );
        $plugin_data = reset( $plugin_data );

        if ( $plugin_data['Version'] ) {
            /* translators: %s: Plugin version. */
            $status['newVersion'] = sprintf( __( 'Version %s' )$plugin_data['Version'] );
        }

        wp_send_json_success( $status );
    } elseif ( false === $result ) {
        global $wp_filesystem;

        

    private function get_plugin( $extension ) {
        if ( ! function_exists( 'get_plugins' ) ) {
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }

        $plugins = get_plugins();

        // Assume plugin main file name first since it is a common convention.         if ( isset( $plugins[ "{$extension['slug']}/{$extension['slug']}.php" ] ) ) {
            return $plugins[ "{$extension['slug']}/{$extension['slug']}.php" ];
        } else {
            foreach ( $plugins as $file => $plugin_data ) {
                if ( str_starts_with( $file, "{$extension['slug']}/" ) || $file === $extension['slug'] ) {
                    return $plugin_data;
                }
            }
        }

        
Home | Imprint | This part of the site doesn't use cookies.