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 walk_category_dropdown_tree( *AllArgs ): ''' Retrieve HTML dropdown (select) content for category list. @uses Walker_CategoryDropdown to create HTML dropdown content. @see Walker_CategoryDropdown::walk() for parameters and return description. @return string ''' args = Php.func_get_args( AllArgs ) # = array( *AllArgs ) # the user's options are the third parameter if Php.empty( args[2]['walker'] ) or not isinstance( args[2]['walker'], Walker ): walker = Walker_CategoryDropdown() else: walker = args[2]['walker'] return Php.call_user_func_array( array( walker, 'walk' ), args )
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