$action();
//call_user_func( array( $section, $action ) );
}
}
/**
* Init Hook
*/
add_action( 'init', 'mf_init' );
if ( !function_exists('mf_init') ) {
function mf_init() {
//Sometimes is neccesary execute the mf_dispatcher function in the init hook
//because we want use a custom headers or a redirect (wp_safe_redirect for eg)
if(!empty($_GET['init']) && $_GET['init'] == "true" ) {
mf_dispatcher();
}
}
}
//Including javascripts files
add_action( 'init', 'mf_add_js');
if ( !function_exists('mf_add_js') ) {
function mf_add_js() {
global $mf_domain;
if( is_admin() ) { //this scripts only will be added on the admin area
wp_enqueue_script( 'jquery.validate',MF_BASENAME.'js/third_party/jquery.validate.min.js', array( 'jquery' ) );
wp_enqueue_script( 'jquery.metadata',MF_BASENAME.'js/third_party/jquery.metadata.js', array( 'jquery' ) );
wp_enqueue_script( 'mf_admin',MF_BASENAME.'js/mf_admin.js', array( 'jquery.validate', 'jquery.metadata', 'jquery' ) );
// add stringToSlug
if( isset($_GET['mf_action']) && in_array($_GET['mf_action'],array('add_field','edit_field', 'add_post_type', 'add_group', 'add_custom_taxonomy') ) ){
wp_enqueue_script( 'jquery.stringToSlug', MF_BASENAME.'js/third_party/jquery.stringToSlug.min.js', array('mf_admin') );
}
//and this scripts only will be added on the default categories
if( !empty( $_GET['mf_action'] ) && $_GET['mf_action'] == "set_categories" ) {
wp_enqueue_script( 'mf_set_categories', MF_BASENAME.'js/mf_set_categories.js', array('mf_admin') );
}
//and this scripts only will be added on the post types section
if( !empty( $_GET['mf_section'] ) && $_GET['mf_section'] == "mf_posttype" ) {
wp_enqueue_script( 'mf_posttype', MF_BASENAME.'js/mf_posttypes.js', array('mf_admin') );
wp_enqueue_script('thickbox');
wp_enqueue_style('thickbox');
}
if( !empty( $_GET['page'] ) && $_GET['page'] == "mf_dispatcher" ) {
wp_enqueue_script('thickbox');
wp_enqueue_style('thickbox');
}
//and this scripts only will be added on the custom taxonomy section
if( !empty( $_GET['mf_section'] ) && $_GET['mf_section'] == "mf_custom_taxonomy" ) {
wp_enqueue_script( 'mf_taxonomy', MF_BASENAME.'js/mf_taxonomy.js', array('mf_admin') );
}
//Adding the files for the sort feature of the custom fields
if( ( !empty( $_GET['mf_section'] ) && $_GET['mf_section'] == 'mf_custom_fields' ) &&
( !empty( $_GET['mf_action'] ) && $_GET['mf_action'] == 'fields_list' ) ) {
wp_enqueue_script( 'mf_sortable_fields', MF_BASENAME.'js/mf_posttypes_sortable.js', array( 'jquery-ui-sortable' ) );
}
// scripts needed for the custom groups
if( ( !empty( $_GET['mf_section'] ) && $_GET['mf_section'] == 'mf_custom_group' ) ){
wp_enqueue_script( 'mf_custom_group', MF_BASENAME.'js/mf_custom_group.js', array('mf_admin') );
}
//Adding Css files for the post-new.php section (where is created a new post in wp)
if( strstr( $_SERVER['REQUEST_URI'], 'post-new.php' ) !== FALSE || strstr( $_SERVER['REQUEST_URI'], 'wp-admin/post.php') !== FALSE ) {
/* Load JS and CSS for post page */
$css_js = new mf_post();
$css_js->load_js_css_base();
$css_js->load_js_css_fields();
$css_js->general_option_multiline();
$css_js->set_categories();
}
}
}
}
add_action('wp_ajax_mf_call','mf_ajax_call');
/* this handle all ajax call of MF */
if ( !function_exists('mf_ajax_call') ) {
function mf_ajax_call(){
$call = new mf_ajax_call();
$call->resolve($_POST);
}
}
add_filter('attachment_fields_to_edit', 'charge_link_after_upload_image', 10, 2);
if ( !function_exists('charge_link_after_upload_image') ) {
function charge_link_after_upload_image($fields){
$wp_version = floatval(get_bloginfo('version'));
if(
$wp_version < 3.5 ||
(( isset($_REQUEST['fetch']) && $_REQUEST['fetch'] ) ||
( isset($_REQUEST['tab']) && $_REQUEST['tab'] == 'library' ))
){
printf("
");
}
return $fields;
}
}
}else{
/* load front-end functions */
require_once( 'mf_front_end.php' );
}
add_filter('plugin_action_links', 'mf_action_links', 10, 2);
// output a settings a link on the plugins page
if ( !function_exists('mf_action_links') ) {
function mf_action_links($links, $file){
//Static so we don't call plugin_basename on every plugin row.
static $this_plugin;
global $mf_domain;
if (!$this_plugin) $this_plugin = plugin_basename(dirname(__FILE__).'/main.php');
if ($file == $this_plugin){
$settings_link = '' . __('Settings', $mf_domain) . '';
array_unshift( $links, $settings_link ); // before other links
}
return $links;
}
}
/**
* This hack give a custom post type the hability
* to choose a custom template
*/
add_action('template_redirect','mf_change_template');
if ( !function_exists('mf_change_template') ) {
function mf_change_template() {
global $post;
// Check global post
if ( empty( $post ) ) {
return;
}
// Process feeds and trackbacks even if not using themes.
if ( is_robots() ) :
do_action('do_robots');
return;
elseif ( is_feed() ) :
do_feed();
return;
elseif ( is_trackback() ) :
include( ABSPATH . 'wp-trackback.php' );
return;
endif;
// Check if the post has a special template
$template = get_post_meta($post->ID, '_wp_mf_page_template', true);
if (!$template || $template == 'default') {
return;
}
$template = TEMPLATEPATH.'/'.$template;
if ( $template = apply_filters( 'template_include', $template ) ) {
include($template);
die();
}
return;
}
}