BP_BuddyBoss_Platform_Updater
Load BuddyBoss Platform Updater class
Description
Source
File: bp-core/classes/class-bp-buddyboss-platform-updater.php
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | class BP_BuddyBoss_Platform_Updater { var $license ; var $api_url ; var $plugin_id = 0; var $plugin_path ; var $plugin_slug ; function __construct( $api_url , $plugin_path , $plugin_id , $license = '' ) { $this ->api_url = $api_url ; $this ->plugin_path = $plugin_path ; $this ->license = $license ; $this ->plugin_id = $plugin_id ; if ( strstr ( $plugin_path , '/' ) ) { list ( $part1 , $part2 ) = explode ( '/' , $plugin_path ); } else { $part2 = $plugin_path ; } $this ->plugin_slug = str_replace ( '.php' , '' , $part2 ); add_filter( 'pre_set_site_transient_update_plugins' , array ( & $this , 'update_plugin' ) ); add_filter( 'plugins_api' , array ( & $this , 'plugins_api' ), 10, 3 ); } function update_plugin( $transient ) { if ( empty ( $transient ->checked ) || empty ( $transient ->checked[ $this ->plugin_path ] ) ) { return $transient ; } $request_data = array ( 'id' => $this ->plugin_id, 'slug' => $this ->plugin_slug, 'version' => $transient ->checked[ $this ->plugin_path ] ); if ( ! empty ( $this ->license ) ) { $request_data [ 'license' ] = $this ->license; } $request_string = $this ->request_call( 'update_check' , $request_data ); $raw_response = wp_remote_post( $this ->api_url, $request_string ); $response = null; if ( ! is_wp_error( $raw_response ) && ( $raw_response [ 'response' ][ 'code' ] == 200 ) ) { $response = unserialize( $raw_response [ 'body' ] ); } //Feed the candy if ( is_object ( $response ) && ! empty ( $response ) ) { $transient ->response[ $this ->plugin_path ] = $response ; return $transient ; } // If there is any same plugin from wordpress.org repository then unset it. if ( isset( $transient ->response[ $this ->plugin_path ] ) ) { if ( strpos ( $transient ->response[ $this ->plugin_path ]->package, 'wordpress.org' ) !== false ) { unset( $transient ->response[ $this ->plugin_path ] ); } } return $transient ; } function plugins_api( $def , $action , $args ) { if ( ! isset( $args ->slug ) || $args ->slug != $this ->plugin_slug ) { return $def ; } $plugin_info = get_site_transient( 'update_plugins' ); $request_data = array ( 'id' => $this ->plugin_id, 'slug' => $this ->plugin_slug, 'version' => ( isset( $plugin_info ->checked ) ) ? $plugin_info ->checked[ $this ->plugin_path ] : 0 // Current version ); if ( ! empty ( $this ->license ) ) { $request_data [ 'license' ] = $this ->license; } $request_string = $this ->request_call( $action , $request_data ); $raw_response = wp_remote_post( $this ->api_url, $request_string ); if ( is_wp_error( $raw_response ) ) { $res = new WP_Error( 'plugins_api_failed' , __( 'An Unexpected HTTP Error occurred during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>' , 'buddyboss' ), $raw_response ->get_error_message() ); } else { $res = unserialize( $raw_response [ 'body' ] ); if ( $res === false ) { $res = new WP_Error( 'plugins_api_failed' , __( 'An unknown error occurred' , 'buddyboss' ), $raw_response [ 'body' ] ); } } return $res ; } function request_call( $action , $args ) { global $wp_version ; return array ( 'body' => array ( 'action' => $action , 'request' => serialize( $args ), 'api-key' => md5( home_url() ) ), 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url() ); } } |
Changelog
Version | Description |
---|---|
BuddyBoss 1.0.0 | Introduced. |
Methods
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.