Type Name: Action

appthemes_init

This hook runs after all theme files have been included, but before anything else is loaded into the theme.

Use the appthemes_init action hook when you want to execute something before the page begins to be rendered.

Usage

This hook provides no parameters. You use this hook by having your function echo output to the browser, or by having it perform background tasks. Your functions shouldn’t return, and shouldn’t take any parameters.

add_action( 'appthemes_init', 'your_function' );

Example: Banned Users

If you do not want certain users to access your site, you can create a hook to check for their IP address, and then use the wp_die() command to stop the page from loading.

function check_banned_user(){
     $banned_user_ip = '192.168.1.1';
 
     // If the user's IP matches, end the request and send a message
     if( $_SERVER['REMOTE_ADDR'] == $banner_user_ip )
        wp_die( __( 'You have been banned.', 'appthemes' ) );
}
 
add_action_hook("appthemes_init", "check_banned_user");

Example: Registering Other Hooks

You can also create a hook to optionally register other hooks. For instance, if you only want to register a hook inside the admin section, you could use the is_admin() function to decide whether or not to register the hook.

function register_my_admin_hook(){
    if( is_admin() ){
        register_hook( 'wp_head' , 'my_function' );
}
 
add_action_hook( 'appthemes_init', 'register_my_admin_hook' );

Changelog

  • since 1.1

Source File

appthemes_init() is located in includes/theme-functions.php.

cp_action_gateway

This function executes in gateways/gateway.php to process the payment.

To learn more about processing payments in ClassiPress, read this tutorial.

Usage

This hook provides the order values to process as the first and only argument. In your code, you need to check the cp_payment_method element of the order values array to make sure it corresponds to your payment processor. If it isn’t, you should return.

function your_payment_processor( $order_values ){
 
    if( $order_values['cp_payment_method'] != "your_payment_processor" ){
        return;
    }
 
    // process order here...
}
add_action( 'cp_action_gateway', 'your_payment_processor', 10, 1 );

Example

<?php
function buy_stuff_processor( $order_values ){
 
    // Only handle BuyStuff payments
    if( $order_values['cp_payment_method'] != "buystuff" ){
        return;
    }
 
    // Process the payment with library function
    bs_process_payment( $order_values );
 
    // Send email with information
    $email = '';
    $email .= __( 'Thanks for purchasing ', 'bs' )  . $order_values['item_name'] . '.';
    $email .= __( ' Your total is ', 'bs' ) . $order_values['item_amount']. '.';
    $email .= __( ' Please come again!', 'bs' );
 
    // Send email with library function
    bs_email_customer( $email );
}
add_action( 'cp_action_gateway', 'buy_stuff_processor', 10, 1 );
?>

Changelog

  • since 1.1

Source File

cp_action_gateway() is located in gateways/gateway.php.

cp_action_payment_method

This function executes in forms/step2.php to allow gateways to hook into the payment selection dropdown.

To learn more about processing payments in ClassiPress, read this tutorial.

Usage

Your code should output an HTML option field.

<?php
function your_payment_option(){
    echo '<option value="your_payment_type">' . __( 'Your Payment Type', 'appthemes' ) . '</option>';
}
add_action( 'cp_action_payment_method', 'your_payment_option' );

Example

<?php
function buystuff_payment_option(){
    if( get_option('bs_enable', false) ){
        echo '<option value="buystuff">' . __( 'BuyStuff', 'bs' ) . '</option>';
    }
}
add_action( 'cp_action_payment_method', 'buystuff_payment_option' );
?>

Changelog

  • since 1.1

Source File

cp_action_payment_method() is located in forms/step2.php.

cp_action_gateway_values

This function executes in gateways/admin-gateway-values.php to allow gateways to hook into the admin gateway options.

To learn more about processing payments in ClassiPress, read this tutorial.

Usage

Your code should modify the global array $action_gateway_values;. This array is made up of instructions to ClassiPress of what to output. Each instruction contains a type parameter, as well as other properties based on the type.

<?php
function your_add_gateway_values(){
        global $action_gateway_values;
 
        $action_gateway_values = array(
            ....
        );
    }
    add_action( 'cp_action_gateway_values', 'bs_add_gateway_values' );

The available types are: tab, tabend, title, logo, text, select, checkbox, textarea, upload, logo, cat_checklist, price_per_cat, required_per_cat, notab, and notabend.

All of this data will be automatically saved to the database on submit, each field under the id attribute that you gave it. For instance, the follow field would be saved under the ‘your_option’ entry, and can be retrieved with get_option( 'your_option' );.

array('type' => 'text',
      'name' => __( 'Your Text Field', 'appthemes' ),
      'id' => 'your_option');

The other attributes for each entry are:

‘tip’ => Tooltip text
‘css’ => Inline styles to be applied to the field
‘req’ => 1 if required, 0 if not
‘min’ => Minimum number of characters allowed before saving data
‘js’ => Inline javascript
‘options’ => An array of dropdown options in value/name format

Checkout the example below to see how some of the types and attributes can be used.

Example: Simple Form

<?php
function bs_add_gateway_values(){
        global $action_gateway_values;
 
        $action_gateway_values = array(
            // Tab Start
            array( 'type' => 'tab',
                   'tabname' => __( 'BuyStuff', 'bs' ), 
                   'id' => ''),
            // Title
            array( 'type' => 'title',
                   'name' => __( 'BuyStuff Options', 'bs' ),
                   'id' => ''),
            // Logo/Picture
            array( 'type' => 'logo',
                   'name' => '<img src="src/to/logo.png" />',
                   'id' => ''),
            // Select Box
            array( 'type' => 'select',
                   'name' => __( 'Enable BuyStuff', 'bs' ),
                   'options' => array(  'yes' => __( 'Yes', 'bs' ),
                                        'no'  => __( 'No', 'bs')),
                   'desc' => __( 'You must have an active BuyStuff account.', 'bs' ),
                   'id' => 'bs_enable'),
            // Text Box
            array( 'type' => 'text',
                   'name' => __( 'BuyStuff Username', 'bs' ),
                   'desc' => __( 'Enter Your BuyStuff Username', 'bs' ),
                   'tip'  => __( 'This is your email address.', 'bs' ),
                   'id' => 'bs_username'),
            array( 'type' => 'tabend',
                   'id' => ''),
        );
    }
    add_action( 'cp_action_gateway_values', 'bs_add_gateway_values' );
?>

Changelog

  • since 1.1

Source File

cp_action_gateway_values()() is located in gateways/admin-gateway-values.php.

appthemes_footer

This function executes in the footer.php file after the WordPress footer hook wp_footer() and loads the entire theme footer code. This function can be overridden and replaced with your own footer instead of the default theme footer.

Usage

This hook provides no parameters. You use this hook by having your function echo output to the browser, or by having it perform background tasks. Your functions shouldn’t return, and shouldn’t take any parameters.

add_action( 'appthemes_footer', 'your_function' );

Example

function unhook_appthemes_functions() {
  // let's remove the default ClassiPress theme footer
  remove_action('appthemes_footer', 'cp_do_footer');
}
 
add_action('init','unhook_appthemes_functions');
 
 
// use this custom footer instead
function insert_your_own_footer() { 
  // some footer code here
}
add_action( 'appthemes_footer', 'insert_your_own_footer' );

Changelog

  • since 1.1

Source File

appthemes_footer() is located in footer.php.

appthemes_after_footer

This function executes in the footer.php file and loads after the WordPress footer hook wp_footer() and the main footer widgets and/or text.

appthemes_after_footer();

Example: Google Analytics

You can use this action hook to place analytics tracking software such as Google Analytics.

<?php
function insert_google_analytics() { 
    ?>
        <script type="text/javascript">
          // Google Analytics Code Here
        </script>
    <?php
}
add_action( 'appthemes_after_footer', 'insert_google_analytics' ); 
?>

Changelog

  • since 1.1

Source File

appthemes_after_footer() is located in footer.php.

appthemes_before_footer

This function executes in the footer.php file and loads before the WordPress footer hook wp_footer() and the main footer widgets and/or text.

appthemes_before_footer();

Example: Google Analytics

You can use this action hook to place analytics tracking software such as Google Analytics.

<?php
function insert_google_analytics() { 
    ?>
        <script type="text/javascript">
          // Google Analytics Code Here
        </script>
    <?php
}
add_action( 'appthemes_after_footer', 'insert_google_analytics' ); 
?>

Changelog

  • since 1.1

Source File

appthemes_before_footer() is located in footer.php.

appthemes_after_sidebar_widgets

This function executes in the sidebar files (sidebar.php, sidebar-user.php, sidebar-blog.php, etc) and loads after the dynamic sidebar code.

appthemes_after_sidebar_widgets();

Example: Twitter Widget

You can add a Twitter Widget or link to your Twitter using this hook. You might also want to look at the pre-loaded widgets provided in each theme.

<?php
function insert_twitter_link() { 
    echo '<a href="http://twitter.com/myusername">' . __( 'Visit me on Twitter!', 'appthemes' ) . '</a>';
}
add_action( 'appthemes_after_sidebar_widgets', 'insert_twitter_link' ); 
?>

Changelog

  • since 1.1

Source File

appthemes_after_sidebar_widgets() is located in all sidebar.php files.

appthemes_before_sidebar_widgets

This function executes in the sidebar files (sidebar.php, sidebar-user.php, sidebar-blog.php, etc) and loads before the dynamic sidebar code.

appthemes_before_sidebar_widgets();

Example: Twitter Widget

You can add a Twitter Widget or link to your Twitter using this hook. You might also want to look at the pre-loaded widgets provided in each theme.

<?php
function insert_twitter_link() { 
    echo '<a href="http://twitter.com/myusername">' . __( 'Visit me on Twitter!', 'appthemes' ) . '</a>';
}
add_action( 'appthemes_before_sidebar_widgets', 'insert_twitter_link' ); 
?>

Changelog

  • since 1.1

Source File

appthemes_before_sidebar_widgets() is located in all sidebar.php files.

appthemes_before_respond

This function executes in the comments-[post_type].php file and loads before the custom post type comments respond form.

appthemes_before_respond();

Example: Legal Disclaimers

You can use this hook to add things like legal disclaimers or other information your readers should know before commenting.

<?php
function insert_comments_disclaimer() { 
    echo '<div class="disclaimer">' . __( 'Comments will be moderated and approved upon author\'s discretion.', 'appthemes' ) . '</div>';
}
add_action( 'appthemes_before_respond', 'insert_comments_disclaimer' ); 
?>

Changelog

  • since 1.1

Source File

appthemes_before_respond() is located in comments-[post_type].php.