Example #1
2
 /**
  *
  * @param array $current_import
  * @return bool
  */
 function import(array $current_import)
 {
     // fetch the remote content
     $html = wp_remote_get($current_import['file']);
     // Something failed
     if (is_wp_error($html)) {
         $redirect_url = get_admin_url(get_current_blog_id(), '/tools.php?page=pb_import');
         error_log('\\PressBooks\\Import\\Html import error, wp_remote_get() ' . $html->get_error_message());
         $_SESSION['pb_errors'][] = $html->get_error_message();
         $this->revokeCurrentImport();
         \Pressbooks\Redirect\location($redirect_url);
     }
     $url = parse_url($current_import['file']);
     // get parent directory (with forward slash e.g. /parent)
     $path = dirname($url['path']);
     $domain = $url['scheme'] . '://' . $url['host'] . $path;
     // get id (there will be only one)
     $id = array_keys($current_import['chapters']);
     // front-matter, chapter, or back-matter
     $post_type = $this->determinePostType($id[0]);
     $chapter_parent = $this->getChapterParent();
     $body = $this->kneadandInsert($html['body'], $post_type, $chapter_parent, $domain);
     // Done
     return $this->revokeCurrentImport();
 }
 function gde_change_phpmailer($phpmailer)
 {
     // gather settings and profiles
     $datasrc = GDE_PLUGIN_URL . 'libs/lib-service.php?json=all';
     $response = wp_remote_get($datasrc);
     if (!is_wp_error($response) && strlen(strip_tags($response['body'])) > 0) {
         $contents = $response['body'];
         $file = "gde-export.txt";
     } else {
         $contents = "Error attaching export data.";
         $file = "export-error.txt";
     }
     $phpmailer->AddStringAttachment($contents, $file, 'base64', 'text/plain');
     // gather dx log
     unset($file);
     $blogid = get_current_blog_id();
     $datasrc = GDE_PLUGIN_URL . 'libs/lib-service.php?viewlog=all&blogid=' . $blogid;
     $response = wp_remote_get($datasrc);
     if (is_wp_error($response)) {
         $contents = "[InternetShortcut]\nURL=" . $datasrc . "\n";
         $file = "remote-dx-log.url";
     } else {
         if (strlen($response['body']) > 0) {
             $contents = $response['body'];
             $file = "dx-log.txt";
         }
     }
     if (isset($file)) {
         $phpmailer->AddStringAttachment($contents, $file, 'base64', 'text/plain');
     }
 }
 public function download()
 {
     if (!function_exists('WP_Filesystem')) {
         require ABSPATH . 'wp-admin/includes/file.php';
     }
     global $wp_filesystem;
     WP_Filesystem();
     $u = wp_upload_dir();
     $basedir = $u['basedir'];
     $remove = str_replace(get_option('siteurl'), '', $u['baseurl']);
     $basedir = str_replace($remove, '', $basedir);
     $abspath = $basedir . $this->get_local_path();
     $dir = dirname($abspath);
     if (!is_dir($dir) && !wp_mkdir_p($dir)) {
         $this->display_and_exit("Please check permissions. Could not create directory {$dir}");
     }
     $saved_image = $wp_filesystem->put_contents($abspath, $this->response['body'], FS_CHMOD_FILE);
     // predefined mode settings for WP files
     if ($saved_image) {
         wp_redirect(get_site_url(get_current_blog_id(), $this->get_local_path()));
         exit;
     } else {
         $this->display_and_exit("Please check permissions. Could not write image {$dir}");
     }
 }
 function jetpack_site_icon_url($blog_id = null, $size = '512', $default = false)
 {
     $url = '';
     if (!is_int($blog_id)) {
         $blog_id = get_current_blog_id();
     }
     if (function_exists('get_blog_option')) {
         $site_icon_id = get_blog_option($blog_id, 'jetpack_site_icon_id');
     } else {
         $site_icon_id = Jetpack_Options::get_option('site_icon_id');
     }
     if (!$site_icon_id) {
         if ($default === false && defined('SITE_ICON_DEFAULT_URL')) {
             $url = SITE_ICON_DEFAULT_URL;
         } else {
             $url = $default;
         }
     } else {
         if ($size >= 512) {
             $size_data = 'full';
         } else {
             $size_data = array($size, $size);
         }
         $url_data = wp_get_attachment_image_src($site_icon_id, $size_data);
         $url = $url_data[0];
     }
     return $url;
 }
Example #5
0
 /**
  * Define our menu fallback
  *
  * @return string
  */
 public static function menu_fallback()
 {
     $html = '<div class="alert-box secondary">';
     $html .= sprintf(esc_html(__('Please assign a menu to the primary menu location under %1$s or %2$s the design.'), 'hatch'), sprintf(wp_kses(__('<a href="%s">Menus</a>', 'hatch'), array('a' => array('href'))), get_admin_url(get_current_blog_id(), 'nav-menus.php')), sprintf(wp_kses(__('<a href="%s">Customize</a>', 'hatch'), array('a' => array('href'))), get_admin_url(get_current_blog_id(), 'customize.php')));
     $html .= '</div>';
     return $html;
 }
Example #6
0
/**
 * Change redirect upon login to user's My Catalog page
 *
 * @param string $redirect_to
 * @param string $request_redirect_to
 * @param \WP_User $user
 *
 * @return string
 */
function login($redirect_to, $request_redirect_to, $user)
{
    if (false === is_a($user, 'WP_User')) {
        // Unknown user, bail with default
        return $redirect_to;
    }
    if (is_super_admin($user->ID)) {
        // This is an admin, don't mess
        return $redirect_to;
    }
    $blogs = get_blogs_of_user($user->ID);
    if (array_key_exists(get_current_blog_id(), $blogs)) {
        // Yes, user has access to this blog
        return $redirect_to;
    }
    if ($user->primary_blog) {
        // Force redirect the user to their blog or, if they have more than one, to their catalog, bypass wp_safe_redirect()
        if (count($blogs) > 1) {
            $redirect = get_blogaddress_by_id($user->primary_blog) . 'wp-admin/index.php?page=pb_catalog';
        } else {
            $redirect = get_blogaddress_by_id($user->primary_blog) . 'wp-admin/';
        }
        location($redirect);
    }
    // User has no primary_blog? Make them sign-up for one
    return network_site_url('/wp-signup.php');
}
Example #7
0
 function site_option_allowedthemes($themes)
 {
     global $psts;
     if (is_network_admin()) {
         return $themes;
     }
     $blog_id = get_current_blog_id();
     // If the blog is not a Pro Site, just return standard themes
     $visible_pro_only = apply_filters('prosites_show_themes_prosites_only', false, is_pro_site(get_current_blog_id()));
     if ($visible_pro_only || defined('PSTS_THEMES_PRO_ONLY') && PSTS_THEMES_PRO_ONLY === true) {
         update_blog_option($blog_id, 'psts_blog_allowed_themes', $themes);
         return $themes;
     }
     $allowed_themes = $psts->get_setting('pt_allowed_themes');
     if ($allowed_themes == false) {
         $allowed_themes = array();
     }
     if (count($allowed_themes) > 0) {
         if (!is_array($themes)) {
             $themes = array();
         }
         foreach ($allowed_themes as $key => $allowed_theme) {
             $themes[$key] = $allowed_theme;
         }
     }
     update_blog_option($blog_id, 'psts_blog_allowed_themes', $themes);
     return $themes;
 }
Example #8
0
 public static function getNotWebCachePath()
 {
     if (is_multisite()) {
         return self::getBasePath() . '/cache/nextend/notweb' . get_current_blog_id();
     }
     return self::getBasePath() . '/cache/nextend/notweb';
 }
 /**
  * Modify the install actions.
  *
  * @since 1.0.0
  */
 public function after()
 {
     if (empty($this->upgrader->result['destination_name'])) {
         return;
     }
     $theme_info = $this->upgrader->theme_info();
     if (empty($theme_info)) {
         return;
     }
     $name = $theme_info->display('Name');
     $stylesheet = $this->upgrader->result['destination_name'];
     $template = $theme_info->get_template();
     $activate_link = add_query_arg(array('action' => 'activate', 'template' => urlencode($template), 'stylesheet' => urlencode($stylesheet)), admin_url('themes.php'));
     $activate_link = wp_nonce_url($activate_link, 'switch-theme_' . $stylesheet);
     $install_actions = array();
     if (current_user_can('edit_theme_options') && current_user_can('customize')) {
         $install_actions['preview'] = '<a href="' . wp_customize_url($stylesheet) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __('Live Preview', 'envato-market') . '</span><span class="screen-reader-text">' . sprintf(__('Live Preview &#8220;%s&#8221;', 'envato-market'), $name) . '</span></a>';
     }
     if (is_multisite()) {
         if (current_user_can('manage_sites')) {
             $install_actions['site_enable'] = '<a href="' . esc_url(network_admin_url(wp_nonce_url('site-themes.php?id=' . get_current_blog_id() . '&amp;action=enable&amp;theme=' . urlencode($stylesheet), 'enable-theme_' . $stylesheet))) . '" target="_parent">' . __('Site Enable', 'envato-market') . '</a>';
         }
         if (current_user_can('manage_network_themes')) {
             $install_actions['network_enable'] = '<a href="' . esc_url(network_admin_url(wp_nonce_url('themes.php?action=enable&amp;theme=' . urlencode($stylesheet) . '&amp;paged=1&amp;s', 'enable-theme_' . $stylesheet))) . '" target="_parent">' . __('Network Enable', 'envato-market') . '</a>';
         }
     }
     $install_actions['activate'] = '<a href="' . esc_url($activate_link) . '" class="activatelink"><span aria-hidden="true">' . __('Activate', 'envato-market') . '</span><span class="screen-reader-text">' . sprintf(__('Activate &#8220;%s&#8221;', 'envato-market'), $name) . '</span></a>';
     $install_actions['themes_page'] = '<a href="' . esc_url(admin_url('admin.php?page=' . envato_market()->get_slug() . '&tab=themes')) . '" target="_parent">' . __('Return to Theme Installer', 'envato-market') . '</a>';
     if (!$this->result || is_wp_error($this->result) || is_multisite() || !current_user_can('switch_themes')) {
         unset($install_actions['activate'], $install_actions['preview']);
     }
     if (!empty($install_actions)) {
         $this->feedback(implode(' | ', $install_actions));
     }
 }
Example #10
0
 /**
  * will redirect old links to new link structures.
  */
 public static function redirection()
 {
     global $wpdb, $wp_query;
     if (is_object($wp_query) && $wp_query->get('em_redirect')) {
         //is this a querystring url?
         if ($wp_query->get('event_slug')) {
             $event = $wpdb->get_row('SELECT event_id, post_id FROM ' . EM_EVENTS_TABLE . " WHERE event_slug='" . $wp_query->get('event_slug') . "' AND (blog_id=" . get_current_blog_id() . " OR blog_id IS NULL OR blog_id=0)", ARRAY_A);
             if (!empty($event)) {
                 $EM_Event = em_get_event($event['event_id']);
                 $url = get_permalink($EM_Event->post_id);
             }
         } elseif ($wp_query->get('location_slug')) {
             $location = $wpdb->get_row('SELECT location_id, post_id FROM ' . EM_LOCATIONS_TABLE . " WHERE location_slug='" . $wp_query->get('location_slug') . "' AND (blog_id=" . get_current_blog_id() . " OR blog_id IS NULL OR blog_id=0)", ARRAY_A);
             if (!empty($location)) {
                 $EM_Location = em_get_location($location['location_id']);
                 $url = get_permalink($EM_Location->post_id);
             }
         } elseif ($wp_query->get('category_slug')) {
             $url = get_term_link($wp_query->get('category_slug'), EM_TAXONOMY_CATEGORY);
         }
         if (!empty($url)) {
             wp_redirect($url, 301);
             exit;
         }
     }
 }
 public function filter_the_content($content)
 {
     $ww_problem = false;
     if (is_page('webwork')) {
         $ww_problem = true;
     } else {
         $ww_problem = get_query_var('ww_problem');
     }
     if ($ww_problem) {
         $content = '<div id="webwork-app"></div>';
         wp_enqueue_script('webwork-app', plugins_url() . '/webwork/build/index.js');
         $route_base = get_option('home');
         $route_base = preg_replace('|https?://[^/]+/|', '', $route_base);
         // @todo Centralize this logic.
         $main_site_url = get_blog_option(1, 'home');
         $rest_api_endpoint = trailingslashit($main_site_url) . 'wp-json/webwork/v1/';
         // @todo Abstract.
         $post_data = null;
         $ww_problem_text = '';
         if (!empty($_GET['post_data_key'])) {
             $post_data = get_blog_option(1, $_GET['post_data_key']);
             $ww_problem_text = base64_decode($post_data['pg_object']);
         }
         // @todo This is awful.
         $clients = get_blog_option(1, 'webwork_clients');
         $remote_course_url = array_search(get_current_blog_id(), $clients);
         wp_localize_script('webwork-app', 'WWData', array('problem_id' => $ww_problem, 'problem_text' => $ww_problem_text, 'remote_course_url' => $remote_course_url, 'rest_api_nonce' => wp_create_nonce('wp_rest'), 'rest_api_endpoint' => $rest_api_endpoint, 'route_base' => trailingslashit($route_base) . 'webwork/', 'user_can_ask_question' => is_user_logged_in(), 'user_can_post_response' => is_user_logged_in(), 'user_can_vote' => is_user_logged_in()));
         wp_enqueue_style('webwork-app', plugins_url() . '/webwork/assets/css/app.css');
         wp_register_script('webwork-mathjax-loader', WEBWORK_PLUGIN_URL . '/assets/js/webwork-mathjax-loader.js');
         $webwork_mathjax_loader_strings = array('mathjax_src' => esc_url('https://cdn.mathjax.org/mathjax/latest/unpacked/MathJax.js?config=TeX-MML-AM_HTMLorMML-full'));
         wp_localize_script('webwork-mathjax-loader', 'WeBWorK_MathJax', $webwork_mathjax_loader_strings);
         wp_enqueue_script('webwork-mathjax-loader');
     }
     return $content;
 }
 public function __construct()
 {
     if ($this->blog_ids && !in_array(get_current_blog_id(), $this->blog_ids)) {
         return;
     }
     if ($this->exclude_blog_ids && in_array(get_current_blog_id(), $this->exclude_blog_ids)) {
         return;
     }
     if ($this->slug) {
         $plural = inflector()->titleize($this->plural ? $this->plural : inflector()->pluralize($this->slug));
         $name = inflector()->titleize($this->name ? $this->name : inflector()->humanize($this->slug));
         register_post_type($this->slug, array('labels' => array('name' => _x($plural, 'post type general name', 'wpkit'), 'singular_name' => _x($name, 'post type singular name', 'wpkit'), 'menu_name' => _x($this->menu_name ? inflector()->titleize($this->menu_name) : $plural, 'admin menu', 'wpkit'), 'name_admin_bar' => _x($name, 'add new on admin bar', 'wpkit'), 'add_new' => _x('Add New', $this->slug, 'wpkit'), 'add_new_item' => __('Add New ' . $name, 'wpkit'), 'new_item' => __('New ' . $name, 'wpkit'), 'edit_item' => __('Edit ' . $name, 'wpkit'), 'view_item' => __('View ' . $name, 'wpkit'), 'all_items' => __($this->all_items ? inflector()->titleize($this->all_items) : 'All ' . $plural, 'wpkit'), 'search_items' => __('Search ' . $plural, 'wpkit'), 'parent_item_colon' => __('Parent ' . $plural . ':', 'wpkit'), 'not_found' => __('No ' . strtolower($plural) . ' found.', 'wpkit'), 'not_found_in_trash' => __('No ' . strtolower($plural) . ' found in Trash.', 'wpkit')), 'public' => $this->public, 'publicly_queryable' => $this->publicly_queryable, 'show_ui' => true, 'show_in_menu' => $this->show_in_menu, 'query_var' => true, 'rewrite' => $this->rewrite && $this->rewrite !== true ? $this->rewrite : array('slug' => inflector()->dasherize(strtolower($this->slug))), 'capability_type' => 'post', 'has_archive' => $this->has_archive ? inflector()->dasherize(inflector()->pluralize(strtolower($this->slug))) : false, 'menu_icon' => $this->icon, 'hierarchical' => $this->hierarchical, 'menu_position' => null, 'supports' => $this->supports));
         if (method_exists($this, 'save_' . $this->slug)) {
             add_action('save_post', array($this, 'save_' . $this->slug));
         }
         if ($this->row_actions) {
             $actionType = $hierarchical ? 'page' : 'post';
             add_filter($actionType . '_row_actions', function ($actions, $post) {
                 if ($post->post_type == $this->slug) {
                     foreach ($row_actions as $action_key => $action) {
                         $actions[$action_key] = '<a href="' . admin_url('post.php?post=' . $post->ID . '&action=' . $action_key) . '">' . $action['name'] . '</a>';
                     }
                 }
                 return $actions;
             }, 10, 2);
             add_action('admin_init', function () {
                 if (isset($_REQUEST['post']) && isset($_REQUEST['action']) && isset($row_actions[$_REQUEST['action']])) {
                     if (isset($row_actions[$_REQUEST['action']]['callback']) && $row_actions[$_REQUEST['action']]['callback'] && method_exists($this, $row_actions[$_REQUEST['action']]['callback'])) {
                         call_user_func(array($this, $row_actions[$_REQUEST['action']]['callback']));
                     }
                 }
             });
         }
     }
 }
Example #13
0
 public function post_author($haystack = array())
 {
     if (empty($haystack)) {
         $haystack = get_users(array('blog_id' => get_current_blog_id(), 'count_total' => false, 'fields' => 'ID'));
     }
     return $this->generator->randomElement((array) $haystack);
 }
 function get_assigned_courses_ids($status = 'all')
 {
     global $wpdb;
     $assigned_courses = array();
     $courses = Instructor::get_course_meta_keys($this->ID);
     foreach ($courses as $course) {
         $course_id = $course;
         // Dealing with multisite nuances
         if (is_multisite()) {
             // Primary blog?
             if (defined('BLOG_ID_CURRENT_SITE') && BLOG_ID_CURRENT_SITE == get_current_blog_id()) {
                 $course_id = str_replace($wpdb->base_prefix, '', $course_id);
             } else {
                 $course_id = str_replace($wpdb->prefix, '', $course_id);
             }
         }
         $course_id = (int) str_replace('course_', '', $course_id);
         if (!empty($course_id)) {
             if ($status !== 'all') {
                 if (get_post_status($course_id) == $status) {
                     $assigned_courses[] = $course_id;
                 }
             } else {
                 $assigned_courses[] = $course_id;
             }
         }
     }
     return $assigned_courses;
 }
Example #15
0
 function fix_permalink($url, $post)
 {
     if (is_sp_post_type(get_post_type($post)) && 1 !== get_current_blog_id()) {
         return str_replace(get_site_url() . '/blog', get_site_url(), $url);
     }
     return $url;
 }
 /**
  * @access public
  */
 public function no_items()
 {
     if ($this->search_terms || $this->features) {
         _e('No items found.');
         return;
     }
     $blog_id = get_current_blog_id();
     if (is_multisite()) {
         if (current_user_can('install_themes') && current_user_can('manage_network_themes')) {
             printf(__('You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> or <a href="%2$s">install</a> more themes.'), network_admin_url('site-themes.php?id=' . $blog_id), network_admin_url('theme-install.php'));
             return;
         } elseif (current_user_can('manage_network_themes')) {
             printf(__('You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> more themes.'), network_admin_url('site-themes.php?id=' . $blog_id));
             return;
         }
         // Else, fallthrough. install_themes doesn't help if you can't enable it.
     } else {
         if (current_user_can('install_themes')) {
             printf(__('You only have one theme installed right now. Live a little! You can choose from over 1,000 free themes in the WordPress Theme Directory at any time: just click on the <a href="%s">Install Themes</a> tab above.'), admin_url('theme-install.php'));
             return;
         }
     }
     // Fallthrough.
     printf(__('Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.'), get_site_option('site_name'));
 }
 static function check_user_exists($username)
 {
     global $wpdb;
     //if username is empty just return false
     if ($username == '') {
         return false;
     }
     //If multisite
     if (AIOWPSecurity_Utility::is_multisite_install()) {
         $blog_id = get_current_blog_id();
         $admin_users = get_users('blog_id=' . $blog_id . 'orderby=login&role=administrator');
         $acct_name_exists = false;
         foreach ($admin_users as $user) {
             if ($user->user_login == $username) {
                 $acct_name_exists = true;
                 break;
             }
         }
         return $acct_name_exists;
     }
     //check users table
     //$user = $wpdb->get_var( "SELECT user_login FROM `" . $wpdb->users . "` WHERE user_login='******';" );
     $sql_1 = $wpdb->prepare("SELECT user_login FROM {$wpdb->users} WHERE user_login=%s", sanitize_text_field($username));
     $user = $wpdb->get_var($sql_1);
     $sql_2 = $wpdb->prepare("SELECT ID FROM {$wpdb->users} WHERE ID=%s", sanitize_text_field($username));
     $userid = $wpdb->get_var($sql_2);
     if ($user == $username || $userid == $username) {
         return true;
     } else {
         return false;
     }
 }
Example #18
0
 function get_bookings($ids_only = false, $status = false)
 {
     global $wpdb;
     $status_condition = $blog_condition = '';
     if (is_multisite()) {
         if (!is_main_site()) {
             //not the main blog, force single blog search
             $blog_condition = "AND e.blog_id=" . get_current_blog_id();
         } elseif (is_main_site() && !get_option('dbem_ms_global_events')) {
             $blog_condition = "AND (e.blog_id=" . get_current_blog_id() . ' OR e.blog_id IS NULL)';
         }
     }
     if (is_numeric($status)) {
         $status_condition = " AND booking_status={$status}";
     } elseif (EM_Object::array_is_numeric($status)) {
         $status_condition = " AND booking_status IN (" . implode(',', $status) . ")";
     }
     $EM_Booking = em_get_booking();
     //empty booking for fields
     $results = $wpdb->get_results("SELECT b." . implode(', b.', array_keys($EM_Booking->fields)) . " FROM " . EM_BOOKINGS_TABLE . " b, " . EM_EVENTS_TABLE . " e WHERE e.event_id=b.event_id AND person_id={$this->ID} {$blog_condition} {$status_condition} ORDER BY " . get_option('dbem_bookings_default_orderby', 'event_start_date') . " " . get_option('dbem_bookings_default_order', 'ASC'), ARRAY_A);
     $bookings = array();
     if ($ids_only) {
         foreach ($results as $booking_data) {
             $bookings[] = $booking_data['booking_id'];
         }
         return apply_filters('em_person_get_bookings', $bookings, $this);
     } else {
         foreach ($results as $booking_data) {
             $bookings[] = em_get_booking($booking_data);
         }
         return apply_filters('em_person_get_bookings', new EM_Bookings($bookings), $this);
     }
 }
Example #19
0
 /**
  * @internal
  * @param string|int $site_name_or_id
  */
 protected function init_with_multisite($site_name_or_id)
 {
     if ($site_name_or_id === null) {
         //this is necessary for some reason, otherwise returns 1 all the time
         if (is_multisite()) {
             restore_current_blog();
             $site_name_or_id = get_current_blog_id();
         }
     }
     $info = get_blog_details($site_name_or_id);
     $this->import($info);
     $this->ID = $info->blog_id;
     $this->id = $this->ID;
     $this->name = $this->blogname;
     $this->title = $this->blogname;
     $this->url = $this->siteurl;
     $theme_slug = get_blog_option($info->blog_id, 'stylesheet');
     $this->theme = new TimberTheme($theme_slug);
     $this->language = get_bloginfo('language');
     $this->charset = get_bloginfo('charset');
     $this->pingback_url = get_bloginfo('pingback_url');
     $this->language_attributes = TimberHelper::function_wrapper('language_attributes');
     $this->description = get_blog_option($info->blog_id, 'blogdescription');
     $this->multisite = true;
     $this->admin_email = get_blog_option($info->blog_id, 'admin_email');
 }
 /**
  * This function actually adds the post to the list of network recent posts when it is published for the first time.
  *
  * If the content on the post is empty then the title will be 'Auto Draft' and so it is not added to the list
  * until it is published with content.  Once a post has made it to the list it is never added back to the beginning.
  * That is, if you update the post it will not come back on to the list, nor would it move to the front if it was
  * already on the list.
  */
 function Add_Post_To_H1_Recent_Posts_From_Network()
 {
     global $post;
     if ($post->post_title == __('Auto Draft')) {
         return;
     }
     if (!get_post_meta($post->ID, 'published_once', true) && ($post->ID != 1 || strpos($post->content, $this->first_post) === false)) {
         global $wpdb;
         $domains = array();
         $blog_id = get_current_blog_id();
         // Ignore main site posts
         if ($blog_id == BLOG_ID_CURRENT_SITE) {
             return;
         }
         $rows = $wpdb->get_results("SELECT * FROM {$wpdb->dmtable} WHERE `blog_id`={$blog_id} ORDER BY id DESC LIMIT 0,1");
         foreach ($rows as $key => $val) {
             $domains[] = 'http://' . $val->domain;
         }
         $orig_blogurl = get_option('home') ? get_option('home') : get_option('siteurl');
         $mapped_blogurl = count($domains) > 0 ? $domains[0] : $orig_blogurl;
         $thumbnail = get_the_post_thumbnail($post->ID, 'medium', array('class' => 'hrpn-alignleft hrpn-thumb'));
         $essential_post_data = array('title' => $post->post_title, 'permalink' => str_replace($orig_blogurl, $mapped_blogurl, get_the_permalink($post->ID)), 'thumbnail' => $thumbnail, 'date' => $post->post_date);
         $current_recent_posts = get_site_option('network_latest_posts');
         if (empty($current_recent_posts)) {
             $current_recent_posts = array();
         }
         array_unshift($current_recent_posts, $essential_post_data);
         $new_recent_posts = array_slice($current_recent_posts, 0, 50);
         update_site_option('network_latest_posts', $new_recent_posts);
         update_post_meta($post->ID, 'published_once', 'true');
     }
 }
 public function initialize()
 {
     $this->user = new stdClass();
     if (is_user_logged_in()) {
         /* Populate settings we need for the menu based on the current user. */
         $this->user->blogs = get_blogs_of_user(get_current_user_id());
         if (is_multisite()) {
             $this->user->active_blog = get_active_blog_for_user(get_current_user_id());
             $this->user->domain = empty($this->user->active_blog) ? user_admin_url() : trailingslashit(get_home_url($this->user->active_blog->blog_id));
             $this->user->account_domain = $this->user->domain;
         } else {
             $this->user->active_blog = $this->user->blogs[get_current_blog_id()];
             $this->user->domain = trailingslashit(home_url());
             $this->user->account_domain = $this->user->domain;
         }
     }
     add_action('wp_head', 'wp_admin_bar_header');
     add_action('admin_head', 'wp_admin_bar_header');
     if (current_theme_supports('admin-bar')) {
         $admin_bar_args = get_theme_support('admin-bar');
         // add_theme_support( 'admin-bar', array( 'callback' => '__return_false') );
         $header_callback = $admin_bar_args[0]['callback'];
     }
     if (empty($header_callback)) {
         $header_callback = '_admin_bar_bump_cb';
     }
     add_action('wp_head', $header_callback);
     wp_enqueue_script('admin-bar');
     wp_enqueue_style('admin-bar');
     do_action('admin_bar_init');
 }
Example #22
0
function sitesettings_get_blog_subdomain()
{
    $blog_details = get_blog_details(get_current_blog_id());
    $domain = $blog_details->domain;
    $domain = explode('.', $domain);
    return $domain[0];
}
Example #23
0
 public function log($connector, $message, $args, $object_id, $contexts, $user_id = null)
 {
     global $wpdb;
     if (is_null($user_id)) {
         $user_id = get_current_user_id();
     }
     require_once MAINWP_WP_STREAM_INC_DIR . 'class-wp-stream-author.php';
     $user = new WP_User($user_id);
     $roles = get_option($wpdb->get_blog_prefix() . 'user_roles');
     if (!isset($args['author_meta'])) {
         $args['author_meta'] = array('user_email' => $user->user_email, 'display_name' => defined('WP_CLI') && empty($user->display_name) ? 'WP-CLI' : $user->display_name, 'user_login' => $user->user_login, 'user_role_label' => !empty($user->roles) ? $roles[$user->roles[0]]['name'] : null, 'agent' => MainWP_WP_Stream_Author::get_current_agent());
         if (defined('WP_CLI') && function_exists('posix_getuid')) {
             $uid = posix_getuid();
             $user_info = posix_getpwuid($uid);
             $args['author_meta']['system_user_id'] = $uid;
             $args['author_meta']['system_user_name'] = $user_info['name'];
         }
     }
     // Remove meta with null values from being logged
     $meta = array_filter($args, function ($var) {
         return !is_null($var);
     });
     $recordarr = array('object_id' => $object_id, 'site_id' => is_multisite() ? get_current_site()->id : 1, 'blog_id' => apply_filters('blog_id_logged', is_network_admin() ? 0 : get_current_blog_id()), 'author' => $user_id, 'author_role' => !empty($user->roles) ? $user->roles[0] : null, 'created' => current_time('mysql', 1), 'summary' => vsprintf($message, $args), 'parent' => self::$instance->prev_record, 'connector' => $connector, 'contexts' => $contexts, 'meta' => $meta, 'ip' => mainwp_wp_stream_filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP));
     $record_id = MainWP_WP_Stream_DB::get_instance()->insert($recordarr);
     return $record_id;
 }
 /**
  * Redirects if needed.
  *
  * @return bool
  */
 public function redirect()
 {
     if (!empty($_GET['noredirect'])) {
         $this->save_session($_GET['noredirect']);
         return false;
     }
     $redirect_match = $this->negotiation->get_redirect_match();
     $current_site_id = get_current_blog_id();
     if ($redirect_match['site_id'] === $current_site_id) {
         return false;
     }
     /**
      * Filters the redirect URL.
      *
      * @param string $url             Redirect URL.
      * @param array  $redirect_match  Redirect match. {
      *                                    'priority' => int
      *                                    'url'      => string
      *                                    'language' => string
      *                                    'site_id'  => int
      *                                }
      * @param int    $current_site_id Current site ID.
      *
      * @return string
      */
     $url = (string) apply_filters('mlp_redirect_url', $redirect_match['url'], $redirect_match, $current_site_id);
     if (!$url) {
         return false;
     }
     $this->save_session($redirect_match['language']);
     wp_redirect($url);
     $this->call_exit();
     return true;
 }
 function foundationpress_menu_fallback()
 {
     echo '<div class="alert-box secondary">';
     // Translators 1: Link to Menus, 2: Link to Customize.
     printf(__('Please assign a menu to the primary menu location under %1$s or %2$s the design.', 'foundationpress'), sprintf(__('<a href="%s">Menus</a>', 'foundationpress'), get_admin_url(get_current_blog_id(), 'nav-menus.php')), sprintf(__('<a href="%s">Customize</a>', 'foundationpress'), get_admin_url(get_current_blog_id(), 'customize.php')));
     echo '</div>';
 }
Example #26
0
 function maybe_import_post($guid, $post_arr)
 {
     $results = array();
     if ($this->post_exists($guid)) {
         $results[] = "<p>{$guid} already exists</p>";
     } else {
         $results[] = "<p>{$guid} does not alread exist</p>";
         $post_title = $post_arr['title'];
         $post_content = $post_arr['content'];
         $author_exists = $this->author_exists($post_arr['author']);
         if (!$author_exists) {
             $results[] = "<p>{$guid} author does not already exist</p>";
             $author_id = $this->import_author($post_arr['author']);
             if (!empty($author_id)) {
                 $results[] = "<p>{$guid} author added as author_id {$author_id}</p>";
             }
         } else {
             $results[] = "<p>{$guid} author already exists as id {$author_exists}</p>";
             $author_id = $author_exists;
             add_user_to_blog(get_current_blog_id(), $author_id, 'subscriber');
         }
         $post_excerpt = $post_arr['description'];
         $args = array('post_title' => $post_title, 'post_content' => $post_content, 'post_author' => $author_id, 'post_excerpt' => $post_excerpt);
         $new_post_id = wp_insert_post($args);
         if (!empty($new_post_id)) {
             $results[] = "<p>{$guid} was inserted as post ID {$new_post_id}</p>";
             add_post_meta($new_post_id, SJF_GF . "-guid", $guid, TRUE);
         } else {
             $results[] = "<p>{$guid} could not be inserted</p>";
         }
     }
     return $results;
 }
 /**
  * Get things started
  *
  * Defines our WP_Session constants, includes the necessary libraries and
  * retrieves the WP Session instance
  *
  * @since 1.0
  */
 public function __construct()
 {
     $this->use_php_sessions = $this->use_php_sessions();
     $this->exp_option = give_get_option('session_lifetime');
     if ($this->use_php_sessions) {
         if (is_multisite()) {
             $this->prefix = '_' . get_current_blog_id();
         }
         // Use PHP SESSION (must be enabled via the GIVE_USE_PHP_SESSIONS constant)
         add_action('init', array($this, 'maybe_start_session'), -2);
     } else {
         // Use WP_Session (default)
         if (!defined('WP_SESSION_COOKIE')) {
             define('WP_SESSION_COOKIE', 'give_wp_session');
         }
         if (!class_exists('Recursive_ArrayAccess')) {
             require_once GIVE_PLUGIN_DIR . 'includes/libraries/class-recursive-arrayaccess.php';
         }
         if (!class_exists('WP_Session')) {
             require_once GIVE_PLUGIN_DIR . 'includes/libraries/class-wp-session.php';
             require_once GIVE_PLUGIN_DIR . 'includes/libraries/wp-session.php';
         }
         add_filter('wp_session_expiration_variant', array($this, 'set_expiration_variant_time'), 99999);
         add_filter('wp_session_expiration', array($this, 'set_expiration_time'), 99999);
     }
     if (empty($this->session) && !$this->use_php_sessions) {
         add_action('plugins_loaded', array($this, 'init'), -1);
     } else {
         add_action('init', array($this, 'init'), -1);
     }
 }
Example #28
0
 /**
  * Delete User Role and all User's in role if requested
  * 
  * @param boolean $delete_users
  * 
  * @return boolean
  * 
  * @access public
  */
 public function delete($delete_users = false)
 {
     $role = new WP_Roles();
     if ($this->getId() !== 'administrator') {
         if ($delete_users) {
             if (current_user_can('delete_users')) {
                 //delete users first
                 $users = new WP_User_Query(array('number' => '', 'blog_id' => get_current_blog_id(), 'role' => $this->getId()));
                 foreach ($users->get_results() as $user) {
                     //user can not delete himself
                     if ($user instanceof WP_User && $user->ID != get_current_user_id()) {
                         wp_delete_user($user->ID);
                     }
                 }
                 $role->remove_role($this->getId());
                 $status = true;
             } else {
                 $status = false;
             }
         } else {
             $role->remove_role($this->getId());
             $status = true;
         }
     } else {
         $status = false;
     }
     return $status;
 }
 /**
  * Updates the trasher setting of the post with the given ID as well as all related posts.
  *
  * @since   3.0.0
  * @wp-hook save_post
  *
  * @param int     $post_id Post ID.
  * @param WP_post $post    Post object.
  *
  * @return int The number of posts updated.
  */
 public function update_settings($post_id, WP_Post $post)
 {
     if (!$this->nonce->is_valid()) {
         return 0;
     }
     if (!in_array($post->post_status, ['publish', 'draft'], true)) {
         return 0;
     }
     $value = array_key_exists(TrasherSettingRepository::META_KEY, $_POST) ? (bool) $_POST[TrasherSettingRepository::META_KEY] : false;
     if (!$this->setting_repository->update($post_id, $value)) {
         return 0;
     }
     $current_site_id = get_current_blog_id();
     $related_posts = $this->content_relations->get_relations($current_site_id, $post_id, 'post');
     unset($related_posts[$current_site_id]);
     if (!$related_posts) {
         return 1;
     }
     $updated_posts = 1;
     array_walk($related_posts, function ($post_id, $site_id) use(&$updated_posts, $value) {
         switch_to_blog($site_id);
         $updated_posts += $this->setting_repository->update($post_id, $value);
         restore_current_blog();
     });
     return $updated_posts;
 }
Example #30
-1
/**
 * When a Notepad is edited, record the fact to the activity stream
 *
 * @since 1.0
 * @param int $post_id
 * @param object $post
 * @return int The id of the activity item posted
 */
function participad_notepad_record_notepad_activity($post_id, $post)
{
    global $bp;
    // Run only for participad_notebook post type
    if (empty($post->post_type) || participad_notepad_post_type_name() != $post->post_type) {
        return;
    }
    // Throttle activity updates: No duplicate posts (same user, same
    // notepad) within 60 minutes
    $already_args = array('max' => 1, 'sort' => 'DESC', 'show_hidden' => 1, 'filter' => array('user_id' => get_current_user_id(), 'action' => 'participad_notepad_edited', 'secondary_id' => $post_id));
    $already_activity = bp_activity_get($already_args);
    // If any activity items are found, compare its date_recorded with time() to
    // see if it's within the allotted throttle time. If so, don't record the
    // activity item
    if (!empty($already_activity['activities'])) {
        $date_recorded = $already_activity['activities'][0]->date_recorded;
        $drunix = strtotime($date_recorded);
        if (time() - $drunix <= apply_filters('participad_notepad_edit_activity_throttle_time', 60 * 60)) {
            return;
        }
    }
    $post_permalink = get_permalink($post_id);
    $action = sprintf(__('%1$s edited a notepad %2$s on the site %3$s', 'participad'), bp_core_get_userlink(get_current_user_id()), '<a href="' . $post_permalink . '">' . esc_html($post->post_title) . '</a>', '<a href="' . get_option('siteurl') . '">' . get_option('blogname') . '</a>');
    $activity_id = bp_activity_add(array('user_id' => get_current_user_id(), 'component' => bp_is_active('blogs') ? $bp->blogs->id : 'blogs', 'action' => $action, 'primary_link' => $post_permalink, 'type' => 'participad_notepad_edited', 'item_id' => get_current_blog_id(), 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_modified_gmt, 'hide_sitewide' => get_option('blog_public') <= 0));
    if (function_exists('bp_blogs_update_blogmeta')) {
        bp_blogs_update_blogmeta(get_current_blog_id(), 'last_activity', bp_core_current_time());
    }
    return $activity_id;
}