some usefull php code from functions.php letrophee

function my_acf_options_page_settings($settings) {
    $settings['title'] = 'Letrophee Options';
    $settings['pages'] = array('Header', 'Footer');

    return $settings;
}

add_filter('acf/options_page/settings', 'my_acf_options_page_settings');

add_filter("wp_nav_menu_objects", 'my_wp_nav_menu_objects_start_in', 10, 2);

# filter_hook function to react on start_in argument

function my_wp_nav_menu_objects_start_in($sorted_menu_items, $args) {
    if (isset($args->start_in)) {
        $menu_item_parents = array();
        foreach ($sorted_menu_items as $key => $item) {
            // init menu_item_parents
            if ($item->object_id == (int) $args->start_in)
                $menu_item_parents[] = $item->ID;

            if (in_array($item->menu_item_parent, $menu_item_parents)) {
                // part of sub-tree: keep!
                $menu_item_parents[] = $item->ID;
            } else {
                // not part of sub-tree: away with it!
                unset($sorted_menu_items[$key]);
            }
        }
        return $sorted_menu_items;
    } else {
        return $sorted_menu_items;
    }
}

function le_add_search_box($items, $args) {

    // only on primary menu
    if (isset($args->add_search)) {
        $items .= '<li class="search">' . get_search_form(FALSE) . '</li>';
    }
    return $items;
}

add_filter('wp_nav_menu_items', 'le_add_search_box', 10, 2);

function al_get_page_by_template($template_name) {
    $pages = get_posts(array(
        'post_type' => 'page',
        'meta_key' => '_wp_page_template',
        'meta_value' => $template_name
    ));
    $pagepid = $pages[0]->ID;
    return $pagepid;
}

if (function_exists('add_image_size')) {
    add_image_size('thumb', 75, 75);
}

function cookie_handler_unset() {
    $cart = filter_input(INPUT_COOKIE, 'letrophee_products', FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^([0-9]+#([0-9])+,)*[0-9]+#[0-9]+$/")));
    global $wpdb;
    $url = explode('/', 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
    $slug = $url[4];
    $postid = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_status='publish' AND post_name = '$slug'");
    $page = get_page_by_title('Thank You');
    if (!$cart || $postid == $page->ID) {
        setcookie("letrophee_products", "", time() - 3600, "/");
    }
}

//add_action('init', 'cookie_handler_unset');

add_action('init', 'do_output_buffer');

function do_output_buffer() {
    ob_start();
}

function remove_acf_menu()
{

    // provide a list of usernames who can edit custom field definitions here
    $admins = array( 
        'alaa'
    );

    // get the current user
    $current_user = wp_get_current_user();

    // match and remove if needed
    if( !in_array( $current_user->user_login, $admins ) )
    {
        remove_menu_page('edit.php?post_type=acf');
remove_menu_page('cpt_main_menu');
    }

}

add_action( 'admin_menu', 'remove_acf_menu', 999 );

 

Leave a Reply

Your email address will not be published. Required fields are marked *