idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
41,900
public function createAsStripeCustomer ( array $ options = [ ] ) { $ options = array_key_exists ( 'email' , $ options ) ? $ options : array_merge ( $ options , [ 'email' => $ this -> email ] ) ; $ customer = StripeCustomer :: create ( $ options , $ this -> getStripeKey ( ) ) ; $ this -> stripe_id = $ customer -> id ; $...
Create a Stripe customer for the given model .
41,901
public function updateStripeCustomer ( array $ options = [ ] ) { $ customer = StripeCustomer :: update ( $ this -> stripe_id , $ options , $ this -> getStripeKey ( ) ) ; return $ customer ; }
Update the underlying Stripe customer information for the model .
41,902
protected function buildPayload ( ) { return array_filter ( [ 'billing_cycle_anchor' => $ this -> billingCycleAnchor , 'coupon' => $ this -> coupon , 'metadata' => $ this -> metadata , 'plan' => $ this -> plan , 'quantity' => $ this -> quantity , 'tax_percent' => $ this -> getTaxPercentageForPayload ( ) , 'trial_end' =...
Build the payload for subscription creation .
41,903
public function getParent ( ) : self { $ parentPath = \ dirname ( $ this -> getPath ( ) ) ; if ( $ parentPath === '.' ) { throw new OutOfRangeException ( 'Cannot get parent of root reference' ) ; } return new self ( $ this -> uri -> withPath ( $ parentPath ) , $ this -> apiClient , $ this -> validator ) ; }
The parent location of a Reference .
41,904
public function getRoot ( ) : self { return new self ( $ this -> uri -> withPath ( '/' ) , $ this -> apiClient , $ this -> validator ) ; }
The root location of a Reference .
41,905
public function getChildKeys ( ) : array { $ snapshot = $ this -> shallow ( ) -> getSnapshot ( ) ; if ( \ is_array ( $ value = $ snapshot -> getValue ( ) ) ) { return array_keys ( $ value ) ; } throw new OutOfRangeException ( sprintf ( '%s has no children with keys' , $ this ) ) ; }
Returns the keys of a reference s children .
41,906
public function push ( $ value = null ) : self { $ value = $ value ?? [ ] ; $ newKey = $ this -> apiClient -> push ( $ this -> uri , $ value ) ; $ newPath = sprintf ( '%s/%s' , $ this -> uri -> getPath ( ) , $ newKey ) ; return new self ( $ this -> uri -> withPath ( $ newPath ) , $ this -> apiClient , $ this -> validat...
Generates a new child location using a unique key and returns its reference .
41,907
public function update ( array $ values ) : self { $ this -> apiClient -> update ( $ this -> uri , $ values ) ; return $ this ; }
Writes multiple values to the database at once .
41,908
public function createUser ( $ properties ) : UserRecord { $ request = $ properties instanceof Request \ CreateUser ? $ properties : Request \ CreateUser :: withProperties ( $ properties ) ; $ response = $ this -> client -> createUser ( $ request ) ; $ uid = JSON :: decode ( ( string ) $ response -> getBody ( ) , true ...
Creates a new user with the provided properties .
41,909
public function updateUser ( $ uid , $ properties ) : UserRecord { $ request = $ properties instanceof Request \ UpdateUser ? $ properties : Request \ UpdateUser :: withProperties ( $ properties ) ; $ request = $ request -> withUid ( $ uid ) ; $ response = $ this -> client -> updateUser ( $ request ) ; $ uid = JSON :: ...
Updates the given user with the given properties .
41,910
public function verifyIdToken ( $ idToken , bool $ checkIfRevoked = null , bool $ allowTimeInconsistencies = null ) : Token { $ checkIfRevoked = $ checkIfRevoked ?? false ; $ allowTimeInconsistencies = $ allowTimeInconsistencies ?? false ; try { $ verifiedToken = $ this -> idTokenVerifier -> verifyIdToken ( $ idToken )...
Verifies a JWT auth token . Returns a Promise with the tokens claims . Rejects the promise if the token could not be verified . If checkRevoked is set to true verifies if the session corresponding to the ID token was revoked . If the corresponding user s session was invalidated a RevokedToken exception is thrown . If n...
41,911
public function revokeRefreshTokens ( $ uid ) { $ uid = $ uid instanceof Uid ? $ uid : new Uid ( $ uid ) ; $ this -> client -> revokeRefreshTokens ( ( string ) $ uid ) ; }
Revokes all refresh tokens for the specified user identified by the uid provided . In addition to revoking all refresh tokens for a user all ID tokens issued before revocation will also be revoked on the Auth backend . Any request with an ID token generated before revocation will be rejected with a token expired error ...
41,912
public static function isValid ( $ value ) : bool { try { self :: decode ( $ value ) ; return true ; } catch ( \ Throwable $ e ) { return false ; } }
Returns true if the given value is a valid JSON string .
41,913
public static function with ( string $ type , string $ value ) : self { $ targetType = strtolower ( $ type ) ; $ new = new self ( ) ; $ new -> type = $ targetType ; switch ( $ targetType ) { case self :: CONDITION : $ new -> value = ( string ) Condition :: fromValue ( $ value ) ; break ; case self :: TOKEN : $ new -> v...
Create a new message target with the given type and value .
41,914
public function getUri ( ) : UriInterface { $ uri = $ this -> reference -> getUri ( ) ; if ( $ this -> sorter ) { $ uri = $ this -> sorter -> modifyUri ( $ uri ) ; } foreach ( $ this -> filters as $ filter ) { $ uri = $ filter -> modifyUri ( $ uri ) ; } return $ uri ; }
Returns the absolute URL for this location .
41,915
public static function ensureJsonSuffix ( ) : callable { return function ( callable $ handler ) { return function ( RequestInterface $ request , array $ options = null ) use ( $ handler ) { $ uri = $ request -> getUri ( ) ; $ path = $ uri -> getPath ( ) ; if ( substr ( $ path , - 5 ) !== '.json' ) { $ uri = $ uri -> wi...
Ensures that the . json suffix is added to URIs and that the content type is set correctly .
41,916
public static function overrideAuth ( Auth $ override ) : callable { return function ( callable $ handler ) use ( $ override ) { return function ( RequestInterface $ request , array $ options = null ) use ( $ handler , $ override ) { return $ handler ( $ override -> authenticateRequest ( $ request ) , $ options ?? [ ] ...
Adds custom authentication to a request .
41,917
public function validate ( $ template ) { $ template = $ template instanceof Template ? $ template : Template :: fromArray ( $ template ) ; $ this -> client -> validateTemplate ( $ template ) ; }
Validates the given template without publishing it .
41,918
public function getReference ( string $ path = null ) : Reference { try { return new Reference ( $ this -> uri -> withPath ( $ path ?? '' ) , $ this -> client ) ; } catch ( \ InvalidArgumentException $ e ) { throw new InvalidArgumentException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } }
Returns a Reference to the root or the specified path .
41,919
public function getReferenceFromUrl ( $ uri ) : Reference { try { $ uri = uri_for ( $ uri ) ; } catch ( \ InvalidArgumentException $ e ) { throw new InvalidArgumentException ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } if ( ( $ givenHost = $ uri -> getHost ( ) ) !== ( $ dbHost = $ this -> uri -> getHost ( ) ) ) {...
Returns a reference to the root or the path specified in url .
41,920
public function getRules ( ) : RuleSet { $ rules = $ this -> client -> get ( $ this -> uri -> withPath ( '.settings/rules' ) ) ; return RuleSet :: fromArray ( $ rules ) ; }
Retrieve Firebase Database Rules .
41,921
public function updateRules ( RuleSet $ ruleSet ) { $ this -> client -> updateRules ( $ this -> uri -> withPath ( '.settings/rules' ) , $ ruleSet ) ; }
Update Firebase Database Rules .
41,922
public function getChild ( string $ path ) : self { $ path = trim ( $ path , '/' ) ; $ expression = '"' . str_replace ( '/' , '"."' , $ path ) . '"' ; $ childValue = search ( $ expression , $ this -> value ) ; return new self ( $ this -> reference -> getChild ( $ path ) , $ childValue ) ; }
Returns another Snapshot for the location at the specified relative path .
41,923
public function validateUri ( UriInterface $ uri ) { $ path = trim ( $ uri -> getPath ( ) , '/' ) ; $ this -> validateDepth ( $ path ) ; foreach ( explode ( '/' , $ path ) as $ key ) { $ this -> validateKeySize ( $ key ) ; $ this -> validateChars ( $ key ) ; } }
Checks the reference URI for invalid properties .
41,924
public function dispatch ( Expression $ expr ) { switch ( true ) { case $ expr instanceof Comparison : return $ this -> walkComparison ( $ expr ) ; case $ expr instanceof Value : return $ this -> walkValue ( $ expr ) ; case $ expr instanceof CompositeExpression : return $ this -> walkCompositeExpression ( $ expr ) ; de...
Dispatches walking an expression to the appropriate handler .
41,925
public static function expr ( ) : ExpressionBuilder { if ( self :: $ expressionBuilder === null ) { self :: $ expressionBuilder = new ExpressionBuilder ( ) ; } return self :: $ expressionBuilder ; }
Returns the expression builder .
41,926
public function andWhere ( Expression $ expression ) : self { if ( $ this -> expression === null ) { return $ this -> where ( $ expression ) ; } $ this -> expression = new CompositeExpression ( CompositeExpression :: TYPE_AND , [ $ this -> expression , $ expression ] ) ; return $ this ; }
Appends the where expression to evaluate when this Criteria is searched for using an AND with previous expression .
41,927
public function orWhere ( Expression $ expression ) : self { if ( $ this -> expression === null ) { return $ this -> where ( $ expression ) ; } $ this -> expression = new CompositeExpression ( CompositeExpression :: TYPE_OR , [ $ this -> expression , $ expression ] ) ; return $ this ; }
Appends the where expression to evaluate when this Criteria is searched for using an OR with previous expression .
41,928
public function orderBy ( array $ orderings ) : self { $ this -> orderings = array_map ( static function ( string $ ordering ) : string { return strtoupper ( $ ordering ) === Criteria :: ASC ? Criteria :: ASC : Criteria :: DESC ; } , $ orderings ) ; return $ this ; }
Sets the ordering of the result of this Criteria .
41,929
public function rename_on_activation ( ) { $ plugin_dir = trailingslashit ( WP_PLUGIN_DIR ) ; $ slug = isset ( $ _GET [ 'plugin' ] ) ? $ _GET [ 'plugin' ] : false ; $ exploded = explode ( '-' , dirname ( $ slug ) ) ; if ( in_array ( 'develop' , $ exploded , true ) ) { $ options = $ this -> get_class_vars ( 'Base' , 'op...
Rename on activation .
41,930
public function can_update ( ) { global $ pagenow ; if ( static :: is_wp_cli ( ) ) { return true ; } $ can_user_update = current_user_can ( 'update_plugins' ) && current_user_can ( 'update_themes' ) ; $ this -> load_options ( ) ; $ admin_pages = [ 'plugins.php' , 'plugin-install.php' , 'themes.php' , 'theme-install.php...
Checks current user capabilities and admin pages .
41,931
public function install_plugin ( $ args , $ assoc_args ) { list ( $ uri ) = $ args ; $ cli_config = $ this -> process_args ( $ uri , $ assoc_args ) ; Singleton :: get_instance ( 'Install' , $ this ) -> install ( 'plugin' , $ cli_config ) ; $ headers = parse_url ( $ uri , PHP_URL_PATH ) ; $ slug = basename ( $ headers )...
Install plugin from GitHub Bitbucket GitLab or Gitea using GitHub Updater .
41,932
private function process_args ( $ uri , $ assoc_args ) { $ token = isset ( $ assoc_args [ 'token' ] ) ? $ assoc_args [ 'token' ] : false ; $ bitbucket_private = isset ( $ assoc_args [ 'bitbucket-private' ] ) ? $ assoc_args [ 'bitbucket-private' ] : false ; $ cli_config = [ ] ; $ cli_config [ 'uri' ] = $ uri ; $ cli_con...
Process WP - CLI config data .
41,933
private function process_branch ( $ cli_config , $ slug ) { $ branch_data [ 'github_updater_branch' ] = $ cli_config [ 'branch' ] ; $ branch_data [ 'repo' ] = $ slug ; Singleton :: get_instance ( 'Branch' , $ this ) -> set_branch_on_install ( $ branch_data ) ; }
Process branch setting for WP - CLI .
41,934
private function decode_response ( $ git , $ response ) { switch ( $ git ) { case 'github' : case 'gitlab' : $ response = isset ( $ response -> content ) ? base64_decode ( $ response -> content ) : $ response ; break ; case 'bbserver' : $ response = isset ( $ response -> lines ) ? $ this -> bbserver_recombine_response ...
Decode API responses that are base64 encoded .
41,935
private function parse_response ( $ git , $ response ) { switch ( $ git ) { case 'bitbucket' : case 'bbserver' : $ response = isset ( $ response -> values ) ? $ response -> values : $ response ; break ; } return $ response ; }
Parse API response that returns as stdClass .
41,936
private function parse_release_asset ( $ git , $ request , $ response ) { switch ( $ git ) { case 'github' : $ download_link = isset ( $ response -> assets [ 0 ] ) && ! is_wp_error ( $ response ) ? $ response -> assets [ 0 ] -> browser_download_url : null ; $ response = ( null !== $ download_link && ( property_exists (...
Parse API response to release asset URI .
41,937
public function get_remote_api_info ( $ git , $ file , $ request ) { $ response = isset ( $ this -> response [ $ file ] ) ? $ this -> response [ $ file ] : false ; if ( ! $ response ) { self :: $ method = 'file' ; $ response = $ this -> api ( $ request ) ; $ response = $ this -> decode_response ( $ git , $ response ) ;...
Read the remote file and parse headers .
41,938
public function get_remote_api_tag ( $ git , $ request ) { $ repo_type = $ this -> return_repo_type ( ) ; $ response = isset ( $ this -> response [ 'tags' ] ) ? $ this -> response [ 'tags' ] : false ; if ( ! $ response ) { self :: $ method = 'tags' ; $ response = $ this -> api ( $ request ) ; if ( ! $ response ) { $ re...
Get remote info for tags .
41,939
public function get_remote_api_changes ( $ git , $ changes , $ request ) { $ response = isset ( $ this -> response [ 'changes' ] ) ? $ this -> response [ 'changes' ] : false ; if ( ! $ response && ! $ this -> can_update_repo ( $ this -> type ) ) { $ response = $ this -> get_local_info ( $ this -> type , $ changes ) ; }...
Read the remote CHANGES . md file .
41,940
public function get_remote_api_readme ( $ git , $ request ) { if ( ! $ this -> local_file_exists ( 'readme.txt' ) ) { return false ; } $ response = isset ( $ this -> response [ 'readme' ] ) ? $ this -> response [ 'readme' ] : false ; if ( ! $ response && ! $ this -> can_update_repo ( $ this -> type ) ) { $ response = $...
Read and parse remote readme . txt .
41,941
public function get_remote_api_branches ( $ git , $ request ) { $ branches = [ ] ; $ response = isset ( $ this -> response [ 'branches' ] ) ? $ this -> response [ 'branches' ] : false ; if ( $ this -> exit_no_update ( $ response , true ) ) { return false ; } if ( ! $ response ) { self :: $ method = 'branches' ; $ respo...
Create array of branches and download links as array .
41,942
public function get_api_release_asset ( $ git , $ request ) { $ response = isset ( $ this -> response [ 'release_asset' ] ) ? $ this -> response [ 'release_asset' ] : false ; if ( $ response && $ this -> exit_no_update ( $ response ) ) { return false ; } if ( ! $ response ) { self :: $ method = 'release_asset' ; $ resp...
Get API release asset download link .
41,943
public function run ( ) { $ this -> load_hooks ( ) ; if ( $ this -> is_current_page ( [ 'options.php' , 'options-general.php' , 'settings.php' ] ) ) { Singleton :: get_instance ( 'Install' , $ this ) -> run ( ) ; Singleton :: get_instance ( 'Remote_Management' , $ this ) -> load_hooks ( ) ; } }
Let s get going .
41,944
private function settings_sub_tabs ( ) { $ subtabs = [ 'github_updater' => esc_html__ ( 'GitHub Updater' , 'github-updater' ) ] ; $ gits = $ this -> get_running_git_servers ( ) ; $ gits [ ] = in_array ( 'gitlabce' , $ gits , true ) ? 'gitlab' : null ; $ gits = array_unique ( $ gits ) ; $ git_subtab = [ ] ; $ ghu_subtab...
Set up the Settings Sub - tabs .
41,945
public function add_plugin_page ( ) { $ parent = is_multisite ( ) ? 'settings.php' : 'options-general.php' ; $ capability = is_multisite ( ) ? 'manage_network' : 'manage_options' ; add_submenu_page ( $ parent , esc_html__ ( 'GitHub Updater Settings' , 'github-updater' ) , esc_html__ ( 'GitHub Updater' , 'github-updater...
Add options page .
41,946
private function options_tabs ( ) { $ current_tab = isset ( $ _GET [ 'tab' ] ) ? esc_attr ( $ _GET [ 'tab' ] ) : 'github_updater_settings' ; echo '<nav class="nav-tab-wrapper" aria-label="Secondary menu">' ; foreach ( $ this -> settings_tabs ( ) as $ key => $ name ) { $ active = ( $ current_tab === $ key ) ? 'nav-tab-a...
Renders setting tabs .
41,947
private function options_sub_tabs ( ) { $ current_tab = isset ( $ _GET [ 'subtab' ] ) ? esc_attr ( $ _GET [ 'subtab' ] ) : 'github_updater' ; echo '<nav class="nav-tab-wrapper" aria-label="Tertiary menu">' ; foreach ( $ this -> settings_sub_tabs ( ) as $ key => $ name ) { $ active = ( $ current_tab === $ key ) ? 'nav-t...
Render the settings sub - tabs .
41,948
public function create_admin_page ( ) { $ action = is_multisite ( ) ? 'edit.php?action=github-updater' : 'options.php' ; $ tab = isset ( $ _GET [ 'tab' ] ) ? esc_attr ( $ _GET [ 'tab' ] ) : 'github_updater_settings' ; $ subtab = isset ( $ _GET [ 'subtab' ] ) ? esc_attr ( $ _GET [ 'subtab' ] ) : 'github_updater' ; $ log...
Options page callback .
41,949
private function admin_page_notices ( ) { $ display = ( isset ( $ _GET [ 'updated' ] ) && is_multisite ( ) ) || isset ( $ _GET [ 'reset' ] ) || isset ( $ _GET [ 'refresh_transients' ] ) ; if ( $ display ) { echo '<div class="updated"><p>' ; } if ( ( isset ( $ _GET [ 'updated' ] ) && '1' === $ _GET [ 'updated' ] ) && is...
Display appropriate notice for Settings page actions .
41,950
public function page_init ( ) { if ( static :: is_doing_ajax ( ) ) { return ; } register_setting ( 'github_updater' , 'github_updater' , [ $ this , 'sanitize' ] ) ; $ this -> ghu_tokens ( ) ; add_settings_section ( 'github_updater_settings' , esc_html__ ( 'GitHub Updater Settings' , 'github-updater' ) , [ $ this , 'pri...
Register and add settings . Check to see if it s a private repo .
41,951
public function ghu_tokens ( ) { $ ghu_options_keys = [ ] ; $ ghu_plugins = Singleton :: get_instance ( 'Plugin' , $ this ) -> get_plugin_configs ( ) ; $ ghu_themes = Singleton :: get_instance ( 'Theme' , $ this ) -> get_theme_configs ( ) ; $ ghu_tokens = array_merge ( $ ghu_plugins , $ ghu_themes ) ; foreach ( $ ghu_t...
Create and return settings fields for private repositories .
41,952
public function unset_stale_options ( $ ghu_options_keys , $ ghu_tokens ) { $ running_servers = $ this -> get_running_git_servers ( ) ; $ ghu_unset_keys = array_diff_key ( static :: $ options , $ ghu_options_keys ) ; $ always_unset = [ 'db_version' , 'branch_switch' , 'github_access_token' , 'github_enterprise_token' ,...
Check current saved options and unset if repos not present .
41,953
private function set_auth_required ( $ token ) { if ( $ token -> enterprise ) { static :: $ auth_required [ 'github_enterprise' ] = static :: $ auth_required [ 'github_enterprise' ] ? : 'github' === $ token -> git ; static :: $ auth_required [ 'gitlab_enterprise' ] = static :: $ auth_required [ 'gitlab_enterprise' ] ? ...
Check to see if it s an enterprise or private repo and set variables .
41,954
public function update_settings ( ) { if ( isset ( $ _POST [ 'option_page' ] ) && 'github_updater' === $ _POST [ 'option_page' ] ) { $ options = $ this -> filter_options ( ) ; update_site_option ( 'github_updater' , $ this -> sanitize ( $ options ) ) ; } do_action ( 'github_updater_update_settings' , $ _POST ) ; $ this...
Update settings for single site or network activated .
41,955
private function filter_options ( ) { $ options = static :: $ options ; if ( ! $ this -> waiting_for_background_update ( ) ) { $ options = array_filter ( $ options , function ( $ e ) { return '1' !== $ e ; } ) ; } $ options = array_merge ( $ options , $ _POST [ 'github_updater' ] ) ; return $ options ; }
Filter options to remove unchecked checkbox options .
41,956
protected function redirect_on_save ( ) { $ update = false ; $ refresh_transients = $ this -> refresh_transients ( ) ; $ reset_api_key = Singleton :: get_instance ( 'Remote_Management' , $ this ) -> reset_api_key ( ) ; $ option_page = apply_filters ( 'github_updater_save_redirect' , [ 'github_updater' ] ) ; if ( ( isse...
Redirect to correct Settings tab on Save .
41,957
private function add_hidden_settings_sections ( $ subtab = [ ] ) { $ subtabs = array_keys ( $ this -> settings_sub_tabs ( ) ) ; $ hide_tabs = array_diff ( $ subtabs , ( array ) $ subtab , [ 'github_updater' ] ) ; if ( ! empty ( $ subtab ) ) { echo '<div id="github_updater" class="hide-github-updater-settings">' ; do_se...
Create settings sections that are hidden . Required to preserve subtab settings during saves .
41,958
private function display_ghu_repos ( $ git ) { $ lock_title = esc_html__ ( 'This is a private repository.' , 'github-updater' ) ; $ broken_title = esc_html__ ( 'This repository has not connected to the API or was unable to connect.' , 'github-updater' ) ; $ dot_org_title = esc_html__ ( 'This repository is hosted on Wor...
Write out listing of installed plugins and themes using GitHub Updater . Places a lock dashicon after the repo name if it s a private repo . Places a WordPress dashicon after the repo name if it s in dot org .
41,959
private function get_language_pack_json ( $ git , $ headers , $ response ) { switch ( $ git ) { case 'github' : $ response = $ this -> api ( '/repos/' . $ headers [ 'owner' ] . '/' . $ headers [ 'repo' ] . '/contents/language-pack.json' ) ; $ response = isset ( $ response -> content ) ? json_decode ( base64_decode ( $ ...
Get language - pack . json from appropriate host .
41,960
public static function http_request_args ( $ args , $ url ) { $ args [ 'sslverify' ] = true ; if ( false === stripos ( $ args [ 'user-agent' ] , 'GitHub Updater' ) ) { $ args [ 'user-agent' ] .= '; GitHub Updater - https://github.com/afragen/github-updater' ; $ args [ 'wp-rest-cache' ] = [ 'tag' => 'github-updater' ] ;...
Adds custom user agent for GitHub Updater .
41,961
public function settings_hook ( $ git ) { add_action ( 'github_updater_add_settings' , function ( $ auth_required ) use ( $ git ) { $ git -> add_settings ( $ auth_required ) ; } ) ; add_filter ( 'github_updater_add_repo_setting_field' , [ $ this , 'add_setting_field' ] , 10 , 2 ) ; }
Add data in Settings page .
41,962
public function add_setting_field ( $ fields , $ repo ) { if ( ! empty ( $ fields ) ) { return $ fields ; } return $ this -> get_repo_api ( $ repo -> git , $ repo ) -> add_repo_setting_field ( ) ; }
Add data to the setting_field in Settings .
41,963
public function get_repo_api ( $ git , $ repo = false ) { $ repo_api = null ; $ repo = $ repo ? : new \ stdClass ( ) ; switch ( $ git ) { case 'github' : $ repo_api = new GitHub_API ( $ repo ) ; break ; case 'bitbucket' : if ( ! empty ( $ repo -> enterprise ) ) { $ repo_api = new Bitbucket_Server_API ( $ repo ) ; } els...
Get repo s API .
41,964
protected function api ( $ url ) { add_filter ( 'http_request_args' , [ $ this , 'http_request_args' ] , 10 , 2 ) ; $ type = $ this -> return_repo_type ( ) ; $ response = wp_remote_get ( $ this -> get_api_url ( $ url ) ) ; $ code = ( int ) wp_remote_retrieve_response_code ( $ response ) ; $ allowed_codes = [ 200 , 404 ...
Call the API and return a json decoded body . Create error messages .
41,965
private function convert_body_string_to_json ( $ response ) { if ( $ this instanceof Gitea_API || $ this instanceof Bitbucket_API || $ this instanceof Bitbucket_Server_API ) { $ body = wp_remote_retrieve_body ( $ response ) ; if ( null === json_decode ( $ body ) ) { $ response [ 'body' ] = json_encode ( $ body ) ; } } ...
Convert response body to JSON .
41,966
protected function return_repo_type ( ) { $ arr = [ ] ; $ arr [ 'type' ] = $ this -> type -> type ; switch ( $ this -> type -> git ) { case 'github' : $ arr [ 'git' ] = 'github' ; $ arr [ 'base_uri' ] = 'https://api.github.com' ; $ arr [ 'base_download' ] = 'https://github.com' ; break ; case 'bitbucket' : $ arr [ 'git...
Return repo data for API calls .
41,967
protected function get_api_url ( $ endpoint , $ download_link = false ) { $ type = $ this -> return_repo_type ( ) ; $ segments = [ 'owner' => $ this -> type -> owner , 'repo' => $ this -> type -> slug , 'branch' => empty ( $ this -> type -> branch ) ? 'master' : $ this -> type -> branch , ] ; foreach ( $ segments as $ ...
Return API url .
41,968
protected function add_access_token_endpoint ( $ git , $ endpoint ) { if ( null === static :: $ options ) { return $ endpoint ; } $ key = null ; $ token = null ; $ token_enterprise = null ; switch ( $ git -> type -> git ) { case 'github' : $ key = 'access_token' ; $ token = 'github_access_token' ; $ token_enterprise = ...
Add appropriate access token to endpoint .
41,969
protected function exit_no_update ( $ response , $ branch = false ) { if ( apply_filters ( 'ghu_always_fetch_update' , false ) ) { return false ; } if ( $ branch ) { return empty ( static :: $ options [ 'branch_switch' ] ) ; } return ! isset ( $ _POST [ 'ghu_refresh_cache' ] ) && ! $ response && ! $ this -> can_update_...
Test to exit early if no update available saves API calls .
41,970
protected function sort_tags ( $ parsed_tags ) { if ( empty ( $ parsed_tags ) ) { return false ; } list ( $ tags , $ rollback ) = $ parsed_tags ; usort ( $ tags , 'version_compare' ) ; krsort ( $ rollback ) ; $ newest_tag = array_slice ( $ tags , - 1 , 1 , true ) ; $ newest_tag_key = key ( $ newest_tag ) ; $ newest_tag...
Sort tags and set object data .
41,971
protected function get_local_info ( $ repo , $ file ) { $ response = false ; if ( isset ( $ _POST [ 'ghu_refresh_cache' ] ) ) { return $ response ; } if ( is_dir ( $ repo -> local_path ) && file_exists ( $ repo -> local_path . $ file ) ) { $ response = file_get_contents ( $ repo -> local_path . $ file ) ; } return $ re...
Get local file info if no update available . Save API calls .
41,972
protected function set_file_info ( $ response ) { $ this -> type -> transient = $ response ; $ this -> type -> remote_version = strtolower ( $ response [ 'Version' ] ) ; $ this -> type -> requires_php = ! empty ( $ response [ 'Requires PHP' ] ) ? $ response [ 'Requires PHP' ] : false ; $ this -> type -> requires = ! em...
Set repo object file info .
41,973
protected function add_meta_repo_object ( ) { $ this -> type -> rating = $ this -> make_rating ( $ this -> type -> repo_meta ) ; $ this -> type -> last_updated = $ this -> type -> repo_meta [ 'last_updated' ] ; $ this -> type -> num_ratings = $ this -> type -> repo_meta [ 'watchers' ] ; $ this -> type -> is_private = $...
Add remote data to type object .
41,974
protected function make_rating ( $ repo_meta ) { $ watchers = ! empty ( $ repo_meta [ 'watchers' ] ) ? $ repo_meta [ 'watchers' ] : 0 ; $ forks = ! empty ( $ repo_meta [ 'forks' ] ) ? $ repo_meta [ 'forks' ] : 0 ; $ open_issues = ! empty ( $ repo_meta [ 'open_issues' ] ) ? $ repo_meta [ 'open_issues' ] : 0 ; $ rating =...
Create some sort of rating from 0 to 100 for use in star ratings . I m really just making this up more based upon popularity .
41,975
protected function set_readme_info ( $ readme ) { foreach ( ( array ) $ this -> type -> sections as $ section => $ value ) { if ( 'description' === $ section ) { continue ; } $ readme [ 'sections' ] [ $ section ] = $ value ; } $ readme [ 'remaining_content' ] = ! empty ( $ readme [ 'remaining_content' ] ) ? $ readme [ ...
Set data from readme . txt . Prefer changelog from CHANGES . md .
41,976
protected function get_release_asset_redirect ( $ asset , $ aws = false ) { if ( ! $ asset ) { return false ; } if ( $ aws && ( time ( ) - strtotime ( '-12 hours' , $ this -> response [ 'timeout' ] ) ) >= 300 ) { unset ( $ this -> response [ 'release_asset_redirect' ] ) ; } $ response = isset ( $ this -> response [ 're...
Return the redirect download link for a release asset . AWS download link sets a link expiration of ONLY 5 minutes .
41,977
public function create_error_message ( $ type = '' ) { global $ pagenow ; $ update_pages = [ 'update-core.php' , 'plugins.php' , 'themes.php' ] ; $ settings_pages = [ 'settings.php' , 'options-general.php' ] ; if ( ( ( ! isset ( $ _GET [ 'page' ] ) || 'github-updater' !== $ _GET [ 'page' ] ) && in_array ( $ pagenow , $...
Display message when API returns other than 200 or 404 .
41,978
public function show_403_error_message ( ) { $ _403 = false ; $ error_code = $ this -> get_error_codes ( ) ; foreach ( ( array ) $ error_code as $ repo ) { if ( ( ! $ _403 && isset ( $ repo [ 'code' ] , $ repo [ 'git' ] ) ) && 403 === $ repo [ 'code' ] && 'github' === $ repo [ 'git' ] ) { $ _403 = true ; if ( ! \ PAnD ...
Create error message for 403 error . Usually 403 as API rate limit max out .
41,979
public function add_endpoints ( $ git , $ endpoint ) { switch ( $ git :: $ method ) { case 'projects' : $ endpoint = add_query_arg ( 'per_page' , '100' , $ endpoint ) ; break ; case 'meta' : case 'tags' : case 'branches' : case 'download_link' : break ; case 'file' : case 'changes' : case 'readme' : $ endpoint = add_qu...
Create GitLab API endpoints .
41,980
public function get_gitlab_id ( ) { $ id = null ; $ response = isset ( $ this -> response [ 'project_id' ] ) ? $ this -> response [ 'project_id' ] : false ; if ( ! $ response ) { self :: $ method = 'projects' ; $ id = implode ( '/' , [ $ this -> type -> owner , $ this -> type -> slug ] ) ; $ id = rawurlencode ( $ id ) ...
Get GitLab project ID and project meta .
41,981
public function parse_changelog_response ( $ response ) { if ( $ this -> validate_response ( $ response ) ) { return $ response ; } $ arr = [ ] ; $ response = [ $ response ] ; array_filter ( $ response , function ( $ e ) use ( & $ arr ) { $ arr [ 'changes' ] = $ e -> content ; } ) ; return $ arr ; }
Parse API response and return array with changelog in base64 .
41,982
public function gitlab_error ( ) { $ auth_required = $ this -> get_class_vars ( 'Settings' , 'auth_required' ) ; $ error_code = $ this -> get_error_codes ( ) ; if ( ! isset ( $ error_code [ 'gitlab' ] ) && ( ( empty ( static :: $ options [ 'gitlab_enterprise_token' ] ) && $ auth_required [ 'gitlab_enterprise' ] ) || ( ...
Generate error message for missing GitLab Private Token .
41,983
public function themes_api ( $ false , $ action , $ response ) { if ( ! ( 'theme_information' === $ action ) ) { return $ false ; } $ theme = isset ( $ this -> config [ $ response -> slug ] ) ? $ this -> config [ $ response -> slug ] : false ; if ( $ this -> waiting_for_background_update ( $ theme ) ) { return $ false ...
Put changelog in themes_api return WP . org data as appropriate .
41,984
public function multisite_branch_switcher ( $ theme_key , $ theme ) { if ( empty ( static :: $ options [ 'branch_switch' ] ) ) { return false ; } $ enclosure = $ this -> update_row_enclosure ( $ theme_key , 'theme' , true ) ; $ id = $ theme_key . '-id' ; $ branches = isset ( $ this -> config [ $ theme_key ] -> branches...
Create branch switcher row for multisite installation .
41,985
public function customize_theme_update_html ( $ prepared_themes ) { foreach ( ( array ) $ this -> config as $ theme ) { if ( empty ( $ prepared_themes [ $ theme -> slug ] ) ) { continue ; } if ( ! empty ( $ prepared_themes [ $ theme -> slug ] [ 'hasUpdate' ] ) ) { $ prepared_themes [ $ theme -> slug ] [ 'update' ] = $ ...
Call theme messaging for single site installation .
41,986
protected function append_theme_actions_content ( $ theme ) { $ details_url = esc_attr ( add_query_arg ( [ 'tab' => 'theme-information' , 'theme' => $ theme -> slug , 'TB_iframe' => 'true' , 'width' => 270 , 'height' => 400 , ] , self_admin_url ( 'theme-install.php' ) ) ) ; $ nonced_update_url = wp_nonce_url ( $ this -...
Create theme update messaging for single site installation .
41,987
public function update_site_transient ( $ transient ) { foreach ( ( array ) $ this -> config as $ theme ) { if ( $ this -> can_update_repo ( $ theme ) ) { $ response = [ 'theme' => $ theme -> slug , 'new_version' => $ theme -> remote_version , 'url' => $ theme -> uri , 'package' => $ theme -> download_link , 'branch' =...
Hook into site_transient_update_themes to update . Finds newest tag and compares to current tag .
41,988
public function run ( ) { if ( null === $ this -> repo ) { return false ; } $ headers = $ this -> parse_header_uri ( $ this -> repo -> languages ) ; $ this -> repo_api -> get_language_pack ( $ headers ) ; add_filter ( 'site_transient_update_plugins' , [ $ this , 'update_site_transient' ] ) ; add_filter ( 'site_transien...
Do the Language Pack integration .
41,989
public function update_site_transient ( $ transient ) { $ locales = get_available_languages ( ) ; $ locales = ! empty ( $ locales ) ? $ locales : [ get_locale ( ) ] ; $ repos = [ ] ; if ( ! isset ( $ transient -> translations ) ) { return $ transient ; } if ( 'site_transient_update_plugins' === current_filter ( ) ) { $...
Add language translations to update_plugins or update_themes transients .
41,990
public function get_current_branch ( $ repo ) { $ current_branch = ! empty ( $ this -> cache [ 'current_branch' ] ) ? $ this -> cache [ 'current_branch' ] : $ repo -> branch ; return $ current_branch ; }
Get the current repo branch .
41,991
public function set_branch_on_switch ( $ repo ) { $ this -> cache = $ this -> get_repo_cache ( $ repo ) ; if ( isset ( $ _GET [ 'action' ] , $ _GET [ 'rollback' ] , $ this -> cache [ 'branches' ] ) && ( 'upgrade-plugin' === $ _GET [ 'action' ] || 'upgrade-theme' === $ _GET [ 'action' ] ) ) { $ current_branch = array_ke...
Set current branch on branch switch .
41,992
public function set_branch_on_install ( $ install ) { $ this -> set_repo_cache ( 'current_branch' , $ install [ 'github_updater_branch' ] , $ install [ 'repo' ] ) ; self :: $ options [ 'current_branch_' . $ install [ 'repo' ] ] = $ install [ 'github_updater_branch' ] ; update_site_option ( 'github_updater' , self :: $ ...
Set current branch on install and update options .
41,993
public function update_plugin ( $ plugin_slug , $ tag = 'master' ) { $ plugin = null ; $ is_plugin_active = false ; foreach ( ( array ) Singleton :: get_instance ( 'Plugin' , $ this ) -> get_plugin_configs ( ) as $ config_entry ) { if ( $ config_entry -> slug === $ plugin_slug ) { $ plugin = $ config_entry ; break ; } ...
Update plugin .
41,994
public function update_theme ( $ theme_slug , $ tag = 'master' ) { $ theme = null ; foreach ( ( array ) Singleton :: get_instance ( 'Theme' , $ this ) -> get_theme_configs ( ) as $ config_entry ) { if ( $ config_entry -> slug === $ theme_slug ) { $ theme = $ config_entry ; break ; } } if ( ! $ theme ) { throw new \ Une...
Update a single theme .
41,995
public function process_request ( ) { $ start = microtime ( true ) ; try { if ( ! isset ( $ _REQUEST [ 'key' ] ) || get_site_option ( 'github_updater_api_key' ) !== $ _REQUEST [ 'key' ] ) { throw new \ UnexpectedValueException ( 'Bad API key.' ) ; } do_action ( 'github_updater_pre_rest_process_request' ) ; $ tag = 'mas...
Process request .
41,996
private function get_local_branch ( ) { $ repo = false ; if ( isset ( $ _REQUEST [ 'plugin' ] ) ) { $ repos = Singleton :: get_instance ( 'Plugin' , $ this ) -> get_plugin_configs ( ) ; $ repo = isset ( $ repos [ $ _REQUEST [ 'plugin' ] ] ) ? $ repos [ $ _REQUEST [ 'plugin' ] ] : false ; } if ( isset ( $ _REQUEST [ 'th...
Returns the current branch of the local repository referenced in the webhook .
41,997
public function add_settings_tabs ( ) { $ install_tabs = [ ] ; if ( current_user_can ( 'install_plugins' ) ) { $ install_tabs [ 'github_updater_install_plugin' ] = esc_html__ ( 'Install Plugin' , 'github-updater' ) ; } if ( current_user_can ( 'install_themes' ) ) { $ install_tabs [ 'github_updater_install_theme' ] = es...
Adds Install tabs to Settings page .
41,998
private function save_options_on_install ( $ install_options ) { self :: $ options = array_merge ( self :: $ options , $ install_options ) ; update_site_option ( 'github_updater' , self :: $ options ) ; }
Save options set during installation .
41,999
private function get_upgrader ( $ type , $ url ) { $ nonce = wp_nonce_url ( $ url ) ; $ upgrader = false ; if ( 'plugin' === $ type ) { $ plugin = self :: $ install [ 'repo' ] ; $ skin = static :: is_wp_cli ( ) ? new CLI_Plugin_Installer_Skin ( ) : new \ Plugin_Installer_Skin ( compact ( 'type' , 'url' , 'nonce' , 'plu...
Get the appropriate upgrader for remote installation .