Changeset 6264
- Timestamp:
- 12/13/2017 07:45:26 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-update-plugin-project-status.php
r4188 r6264 16 16 global $wpdb; 17 17 18 if ( ! defined( ' PLUGINS_TABLE_PREFIX' ) ) {19 WP_CLI::error( ' PLUGINS_TABLE_PREFIXis not defined.' );18 if ( ! defined( 'WPORG_PLUGIN_DIRECTORY_BLOGID' ) ) { 19 WP_CLI::error( 'WPORG_PLUGIN_DIRECTORY_BLOGID is not defined.' ); 20 20 } 21 21 … … 27 27 $plugins = GP::$project->many( "SELECT * FROM {$wpdb->gp_projects} WHERE parent_project_id = %d", $parent_project->id ); 28 28 if ( ! $plugins ) { 29 WP_CLI::error( 'No plugins found s.' );29 WP_CLI::error( 'No plugins found.' ); 30 30 } 31 31 … … 33 33 $plugin_status = $this->get_plugin_status( $plugin->slug ); 34 34 35 if ( 'publish ed' === $plugin_status && ! $plugin->active ) {36 $plugin->save( array(35 if ( 'publish' === $plugin_status && ! $plugin->active ) { 36 $plugin->save( [ 37 37 'active' => 1, 38 ));38 ] ); 39 39 WP_CLI::log( sprintf( 40 40 'Plugin `%s` has been activated.', 41 41 $plugin->slug 42 42 ) ); 43 } elseif ( 'publish ed' !== $plugin_status && $plugin->active ) {44 $plugin->save( array(43 } elseif ( 'publish' !== $plugin_status && $plugin->active ) { 44 $plugin->save( [ 45 45 'active' => 0, 46 ));46 ] ); 47 47 WP_CLI::log( sprintf( 48 48 'Plugin `%s` has been deactivated.', … … 56 56 * Retrieves the current plugin status. 57 57 * 58 * @param $plugin_slug The plugin slug. 59 * 58 * @param string $plugin_slug The plugin slug. 60 59 * @return false|string Status on success, false on failure. 61 60 */ 62 61 protected function get_plugin_status( $plugin_slug ) { 63 global $wpdb; 62 switch_to_blog( WPORG_PLUGIN_DIRECTORY_BLOGID ); 63 $posts = get_posts( [ 64 'post_type' => 'plugin', 65 'name' => $plugin_slug, 66 'post_status' => [ 'publish', 'pending', 'disabled', 'closed', 'new', 'draft', 'approved' ], 67 ] ); 68 restore_current_blog(); 64 69 65 $topic = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . PLUGINS_TABLE_PREFIX . 'topics WHERE topic_slug = %s', $plugin_slug ) ); 66 if ( ! $topic ) { 70 if ( ! $posts ) { 67 71 return false; 68 72 } 69 73 70 $status = 'published'; 71 if ( 2 == $topic->topic_open ) { 72 $status = 'approved'; 73 } elseif ( 2 == $topic->forum_id ) { 74 $status = 'pending'; 75 } elseif ( 4 == $topic->forum_id || 'rejected-' == substr( $topic->topic_slug, 0, 9 ) ) { 76 $status = 'rejected'; 77 } elseif ( 1 == $topic->forum_id && 0 == $topic->topic_open ) { 78 $status = 'closed'; 79 } elseif ( 3 == $topic->topic_open ) { 80 $status = 'disabled'; 81 } 74 $plugin = array_shift( $posts ); 82 75 83 return $ status;76 return $plugin->post_status; 84 77 } 85 78 }
Note: See TracChangeset
for help on using the changeset viewer.