This documentation is for AppPresser 2 only. For AppPresser 3 docs, click here.

Code Snippets

This page lists quick snippets that take care of little things, that don't warrant a full tutorial.

Remove search from left slideout panel

If you wish to remove the search permanently, you can add this to your child theme. This is intended for AppTheme 1.0.3 or lower.

remove_filter( 'appp_left_panel_before', array( AppPresser_Theme_Functions::run()->App_Functionality, 'left_panel_search' ), 20 );

If you're on AppTheme 1.0.4 or higher, the following should work.

function prefix_appp_remove_search() {
    appp_remove_hook( 'appp_left_panel_before', 'left_panel_search', 20 );
}
add_action( 'after_setup_theme', 'prefix_appp_remove_search' );

If you wish to just hide it but not remove it completely, add the following to your style.css file

.shelf-search { display: none; }

Note: hiding via css can be beneficial if you want to offer some way to show with more granular control with jQuery or so.

Prevent access to the website if not within context of app

function limit_access_app() {
    if ( !AppPresser::is_app() && !is_admin() ) {
       echo "You need the app!";
       exit;
    }
}
add_action( 'appp_before', 'limit_access_app' );

Remove file upload from AppCamera on AppWoo products.

function prefix_remove_camera_from_automatic_inclusion() {
    remove_action( 'appp_after_product_images', array( $GLOBALS['AppPresser_WooCommerce']->woocom_mods, 'product_upload_images' ) );
    remove_action( 'appp_after_process_uploads', array( $GLOBALS['AppPresser_WooCommerce']->woocom_mods, 'product_process_uploaded_images' ), 0, 2 );
}
add_action( 'wp_head', 'prefix_remove_camera_from_automatic_inclusion' );

Programatically load a page via ajax in the AppTheme

<script>
window.apppresser.loadAjaxContent( 'http://mysite.com/sample-page' );
</script>

Mapping Function Calls to Specific Pages

When using our Ajax page loading, each time the content is finished loading, we trigger the 'load_ajax_content_done' event. You can attach a listener to that event to execute JavaScript at that time. If you would like some JavaScript to be called only on certain pages you can map functions to URL paths. Since you can get the current path of the URL using location.pathname you can create an array of the paths you want to map to a function (a handler).

var my_page_mapper = [
	{path:'/', handler: init_home},
	{path:'/category/news/', handler: init_news},
];

function init_news() {
	// on the news page: do stuff
}

function init_home() {
	// on the home page: do stuff
}

function init_current_page() {
	var current_path = location.pathname;

	for(var i = 0; i < my_page_mapper.length; i++ ) {
		if( my_page_mapper[i].path == current_path ) {
			my_page_mapper[i].handler();
		}
	}
}

jQuery('body').on('load_ajax_content_done', init_current_page);