function a3_portfolio_set_global_page()
{
    global $wpdb, $portfolio_page_name, $portfolio_page_id;
    $portfolio_page_id = get_option('portfolio_page_id');
    $page_data = null;
    if ($portfolio_page_id != false) {
        $page_data = $wpdb->get_row($wpdb->prepare("SELECT ID, post_name FROM `" . $wpdb->posts . "` WHERE `post_content` LIKE '%[portfoliopage]%' AND `ID` = %d AND `post_type` = 'page' AND `post_status` = 'publish' LIMIT 1", $portfolio_page_id));
    }
    if ($page_data == null) {
        $page_data = $wpdb->get_row("SELECT ID, post_name FROM `" . $wpdb->posts . "` WHERE `post_content` LIKE '%[portfoliopage]%' AND `post_type` = 'page' AND `post_status` = 'publish' ORDER BY ID DESC LIMIT 1");
        if ($page_data) {
            update_option('portfolio_page_id', $page_data->ID);
        }
    }
    if ($page_data == null) {
        $portfolio_page_id_created = a3_portfolio_create_page(esc_sql('portfolios'), '', __('Portfolios', 'a3_portfolios'), '[portfoliopage]');
        update_option('portfolio_page_id', $portfolio_page_id_created);
        $page_data = $wpdb->get_row($wpdb->prepare("SELECT ID, post_name FROM `" . $wpdb->posts . "` WHERE `ID` = %d LIMIT 1", $portfolio_page_id_created));
    }
    $portfolio_page_id = $page_data->ID;
    $portfolio_page_name = $page_data->post_name;
    // For WPML
    if (class_exists('SitePress')) {
        global $sitepress;
        $translation_page_data = null;
        $translation_page_data = $wpdb->get_row($wpdb->prepare("SELECT element_id FROM " . $wpdb->prefix . "icl_translations WHERE trid = %d AND element_type='post_page' AND language_code = %s LIMIT 1", $portfolio_page_id, $sitepress->get_current_language()));
        if ($translation_page_data != null) {
            $portfolio_page_id = $translation_page_data->element_id;
            $portfolio_page_wpml = get_post($portfolio_page_id);
            $portfolio_page_name = $portfolio_page_wpml->post_name;
        }
    }
}
Esempio n. 2
0
 public function plugin_activated()
 {
     update_option('a3_portfolio_version', '1.0.4');
     // Install Database
     include A3_PORTFOLIO_DIR . '/includes/class-a3-portfolio-data.php';
     global $a3_portfolio_data;
     $a3_portfolio_data->install_database();
     $portfolio_page_id_created = a3_portfolio_create_page(_x('portfolios', 'page_slug', 'a3_portfolios'), '', __('Portfolios', 'a3_portfolios'), '[portfoliopage]');
     update_option('portfolio_page_id', $portfolio_page_id_created);
     // Create Portfolio page for languages support by WPML
     a3_portfolio_auto_create_page_for_wpml($portfolio_page_id_created, _x('portfolios', 'page_slug', 'a3_portfolios'), __('Portfolios', 'a3_portfolios'), '[portfoliopage]');
     update_option('a3_portfolio_just_installed', true);
 }