def _wp_call_all_hook(args): ''' Call the 'all' hook, which will process the functions hooked into it. The 'all' hook passes all of the arguments or parameters that were used for the hook, which this function was called for. This function is used internally for apply_filters(), do_action(), and do_action_ref_array() and is not meant to be used from outside those functions. This function does not check for the existence of the all hook, so it will fail unless the all hook exists prior to this function call. @global array wp_filter Stores all of the filters @param array args The collected parameters from the hook that was called. ''' #global var==>WpC.WB.Wj.var, except: var=WpC.WB.Wj.var=same Obj,mutable array wp_filter = WpC.WB.Wj.wp_filter # global wp_filter # No need to reset in py since for loop alawys starts at elem#1 in list #reset( wp_filter['all'] ) #do { #Php: the first iteration of a do-while loop is guaranteed to run # (the truth expression is only checked at the end of the iteration) for Tag in [True, *wp_filter['all']]: if Tag is False: break for the_ in Php.Array(Php.current(wp_filter['all'])): if not Php.is_null(the_['function']): Php.call_user_func_array(the_['function'], args)
def apply_filters_ref_array(tag, args, *OtherArgs): #Orig: ( tag, args ): ''' Execute functions hooked on a specific filter hook, specifying arguments in an array. @see apply_filters() This function is identical, but the arguments passed to the functions hooked to `tag` are supplied using an array. @global array wp_filter Stores all of the filters @global array merged_filters Merges the filter hooks using this function. @global array wp_current_filter Stores the list of current filters with the current one last @param string tag The name of the filter hook. @param array args The arguments supplied to the functions hooked to tag. @return mixed The filtered value after all hooked functions are applied to it. ''' #global var==>WB.Wj.var, except: var=WB.Wj.var=same Obj,mutable array wp_filter = WpC.WB.Wj.wp_filter # global wp_filter merged_filters = WpC.WB.Wj.merged_filters # global merged_filters wp_current_filter = WpC.WB.Wj.wp_current_filter # global wp_current_filter AllArgs = tag, args, *OtherArgs # Do 'all' actions first if Php.isset(wp_filter, 'all'): wp_current_filter.append(tag) # php2python.com/wiki/function.func-get-args/ all_args = Php.func_get_args(AllArgs) _wp_call_all_hook(all_args) if not Php.isset(wp_filter, tag): if Php.isset(wp_filter, 'all'): wp_current_filter.popitem() return args[0] if not Php.isset(wp_filter, 'all'): wp_current_filter.append(tag) # Sort if not Php.isset(merged_filters, tag): wp_filter[tag] = Php.ksort(wp_filter[tag]) merged_filters[tag] = True # No need to reset in py since for loop alawys starts at elem#1 in list #reset( wp_filter[ tag ] ) #do { #Php: the first iteration of a do-while loop is guaranteed to run # (the truth expression is only checked at the end of the iteration) for Tag in [True, *wp_filter[tag]]: if Tag is False: break for the_ in Php.Array(Php.current(wp_filter[tag])): if not Php.is_null(the_['function']): args[0] = Php.call_user_func_array( the_['function'], Php.array_slice(args, 0, int(the_['accepted_args']))) #} while ( next(wp_filter[tag]) is not False ) wp_current_filter.popitem() return args[0]
def delete_option(option): ''' Removes option by name. Prevents removal of protected WordPress options. @global wpdb wpdb WordPress database abstraction object. @param string option Name of option to remove. Expected to not be SQL-escaped @return bool True, if option is successfully deleted. False on failure. ''' wpdb = WpC.WB.Wj.wpdb # global wpdb option = Php.trim(option) if Php.empty(locals(), 'option'): return False wp_protect_special_option(option) # Get the ID, if no ID then return row = wpdb.get_row( wpdb.prepare( "SELECT autoload FROM {} WHERE option_name" " = %s".format(wpdb.options), option)) if Php.is_null(row): return False # Fires immediately before an option is deleted. # @param string option Name of the option to delete. WiPg.do_action('delete_option', option) result = wpdb.delete(wpdb.options, array(('option_name', option))) if not wp_installing(): if 'yes' == row.autoload: alloptions = wp_load_alloptions() if Php.is_array(alloptions) and Php.isset(alloptions, option): del (alloptions[option]) WiCa.wp_cache_set('alloptions', alloptions, 'options') else: WiCa.wp_cache_delete(option, 'options') if result: # Fires after a specific option has been deleted. # The dynamic portion of the hook name, `option`, refers to the option name # @param string option Name of the deleted option. WiPg.do_action("delete_option_" + option, option) # Fires after an option has been deleted. # @param string option Name of the deleted option. WiPg.do_action('deleted_option', option) return True return False
def do_action(tag, arg='', *OtherArgs, Wj=None): ''' Execute functions hooked on a specific action hook. This function invokes all functions attached to action hook `tag`. It is possible to create new action hooks by simply calling this function, specifying the name of the new hook using the `tag` parameter. You can pass extra arguments to the hooks, much like you can with apply_filters(). @global array wp_filter Stores all of the filters @global array wp_actions Increments the amount of times action was triggered. @global array merged_filters Merges the filter hooks using this function. @global array wp_current_filter Stores the list of current filters with the current one last @param string tag The name of the action to be executed. @param mixed arg,... Optional. Additional arguments which are passed on to the functions hooked to the action. Default empty. ''' #global var==>WpC.WB.Wj.var, except: var=WpC.WB.Wj.var=same Obj,mutable array if Wj is None: Wj = WpC.WB.Wj wp_filter = Wj.wp_filter # global wp_filter wp_actions = Wj.wp_actions # global wp_actions merged_filters = Wj.merged_filters # global merged_filters wp_current_filter = Wj.wp_current_filter # global wp_current_filter AllArgs = tag, arg, *OtherArgs if not Php.isset(wp_actions, tag): wp_actions[tag] = 1 else: wp_actions[tag] += 1 # Do 'all' actions first if Php.isset(wp_filter, 'all'): wp_current_filter.append(tag) # php2python.com/wiki/function.func-get-args/ all_args = Php.func_get_args(AllArgs) _wp_call_all_hook(all_args) if not Php.isset(wp_filter, tag): if Php.isset(wp_filter, 'all'): wp_current_filter.popitem() return if not Php.isset(wp_filter, 'all'): wp_current_filter.append(tag) args = array() # 1 == len(arg) #implies: isset(arg[0]) if Php.is_array(arg) and 1 == len(arg) and Php.is_object( arg[0]): # array(&this) #args.append(& arg[0]) # & <<== Check!! # & not needed for object? args.append(arg[0]) else: args.append(arg) #for ( a = 2, num = func_num_args(); a < num; a++ ) for a in range(2, Php.func_num_args(AllArgs)): args[None] = Php.func_get_arg(AllArgs, a) # differ from func_get_args # Sort if not Php.isset(merged_filters, tag): wp_filter[tag] = Php.ksort(wp_filter[tag]) merged_filters[tag] = True # No need to reset in py since for loop alawys starts at elem#1 in list #reset( wp_filter[ tag ] ) #do { #Php: the first iteration of a do-while loop is guaranteed to run # (the truth expression is only checked at the end of the iteration) for Tag in [True, *wp_filter[tag]]: if Tag is False: break for the_ in Php.Array(Php.current(wp_filter[tag])): if not Php.is_null(the_['function']): Php.call_user_func_array( the_['function'], Php.array_slice(args, 0, int(the_['accepted_args']))) #} while ( next(wp_filter[tag]) is not False ) wp_current_filter.popitem()
def apply_filters(tag, value, *OtherArgs, Wj=None): ''' Call the functions added to a filter hook. The callback functions attached to filter hook tag are invoked by calling this function. This function can be used to create a new filter hook by simply calling this function with the name of the new hook specified using the tag parameter. The function allows for additional arguments to be added and passed to hooks. # Our filter callback function function example_callback( string, arg1, arg2 ) { # (maybe) modify string return string } add_filter( 'example_filter', 'example_callback', 10, 3 ) /* * Apply the filters by calling the 'example_callback' function we * "hooked" to 'example_filter' using the add_filter() function above. * - 'example_filter' is the filter hook tag * - 'filter me' is the value being filtered * - arg1 and arg2 are the additional arguments passed to the callback. value = apply_filters( 'example_filter', 'filter me', arg1, arg2 ) @global array wp_filter Stores all of the filters. @global array merged_filters Merges the filter hooks using this function. @global array wp_current_filter Stores the list of current filters with the current one last. @param string tag The name of the filter hook. @param mixed value The value on which the filters hooked to `tag` are applied on. @param mixed var,... Additional variables passed to the functions hooked to `tag`. @return mixed The filtered value after all hooked functions are applied to it. ''' #global var==>WB.Wj.var, except: var=WB.Wj.var=same Obj,mutable array if Wj is None: Wj = WpC.WB.Wj wp_filter = Wj.wp_filter # global wp_filter merged_filters = Wj.merged_filters # global merged_filters wp_current_filter = Wj.wp_current_filter # global wp_current_filter AllArgs = tag, value, *OtherArgs #print("WiPg.apply_filters:", tag, value, OtherArgs) args = array() # Do 'all' actions first. if Php.isset(wp_filter, 'all'): wp_current_filter.append(tag) args = Php.func_get_args(AllArgs) _wp_call_all_hook(args) if not Php.isset(wp_filter, tag): if Php.isset(wp_filter, 'all'): wp_current_filter.popitem() return value if not Php.isset(wp_filter, 'all'): wp_current_filter.append(tag) # Sort. if not Php.isset(merged_filters, tag): wp_filter[tag] = Php.ksort(wp_filter[tag]) merged_filters[tag] = True # No need to reset in py since for loop alawys starts at elem#1 in list Php.reset(wp_filter[tag]) if not args: # Php.empty(locals(), 'args'): args = Php.func_get_args(AllArgs) #do { #Php: the first iteration of a do-while loop is guaranteed to run # (the truth expression is only checked at the end of the iteration) #for Tag in [True, *wp_filter[tag] ]: # if Tag is False: # break for Tag in wp_filter[tag]: if Tag is False: break #for the_ in Php.Array( Php.current(wp_filter[tag])): for the_ in Php.Array(Tag): if not Php.is_null(the_['function']): args[1] = value value = Php.call_user_func_array( the_['function'], Php.array_slice(args, 1, int(the_['accepted_args']))) #} while ( next(wp_filter[tag]) is not False ) wp_current_filter.popitem() return value