/** * Fired for each blog when the plugin is activated. * * @since 1.0.1 * * @param boolean $network_wide True if WPMU superadmin uses * "Network Activate" action, false if * WPMU is disabled or plugin is * activated on an individual blog. */ function crp_activate($network_wide) { global $wpdb; if (is_multisite() && $network_wide) { // Get all blogs in the network and activate plugin on each one $blog_ids = $wpdb->get_col("\n \tSELECT blog_id FROM {$wpdb->blogs}\n\t\t\tWHERE archived = '0' AND spam = '0' AND deleted = '0'\n\t\t"); foreach ($blog_ids as $blog_id) { switch_to_blog($blog_id); crp_single_activate(); } // Switch back to the current blog restore_current_blog(); } else { crp_single_activate(); } }
/** * Fired when a new site is activated with a WPMU environment. * * @since 1.0.0 * * @param int $blog_id ID of the new blog. */ function crpt_activate_new_site($blog_id) { if (1 !== did_action('wpmu_new_blog')) { return; } switch_to_blog($blog_id); crp_single_activate(); restore_current_blog(); }
/** * Fired when a new site is activated with a WPMU environment. * * @since 2.0.0 * * @param int $blog_id ID of the new blog. */ function crp_activate_new_site($blog_id) { if (1 !== did_action('wpmu_new_blog')) { return; } require_once plugin_dir_path(__FILE__) . 'includes/plugin-activator.php'; switch_to_blog($blog_id); crp_single_activate(); restore_current_blog(); }
/** * Function generates the plugin settings page. * * @since 1.0.1 * */ function crp_options() { global $wpdb, $crp_url; $crp_settings = crp_read_options(); $wp_post_types = get_post_types(array('public' => true)); parse_str($crp_settings['post_types'], $post_types); $posts_types_inc = array_intersect($wp_post_types, $post_types); parse_str($crp_settings['exclude_on_post_types'], $exclude_on_post_types); $posts_types_excl = array_intersect($wp_post_types, $exclude_on_post_types); if (isset($_POST['crp_save']) && check_admin_referer('crp-plugin-settings')) { /**** General options ***/ $crp_settings['cache'] = isset($_POST['cache']) ? true : false; $crp_settings['limit'] = intval($_POST['limit']); $crp_settings['daily_range'] = intval($_POST['daily_range']); $crp_settings['match_content'] = isset($_POST['match_content']) ? true : false; $crp_settings['match_content_words'] = intval($_POST['match_content_words']); $crp_settings['add_to_content'] = isset($_POST['add_to_content']) ? true : false; $crp_settings['add_to_page'] = isset($_POST['add_to_page']) ? true : false; $crp_settings['add_to_feed'] = isset($_POST['add_to_feed']) ? true : false; $crp_settings['add_to_home'] = isset($_POST['add_to_home']) ? true : false; $crp_settings['add_to_category_archives'] = isset($_POST['add_to_category_archives']) ? true : false; $crp_settings['add_to_tag_archives'] = isset($_POST['add_to_tag_archives']) ? true : false; $crp_settings['add_to_archives'] = isset($_POST['add_to_archives']) ? true : false; $crp_settings['content_filter_priority'] = intval($_POST['content_filter_priority']); $crp_settings['show_metabox'] = isset($_POST['show_metabox']) ? true : false; $crp_settings['show_metabox_admins'] = isset($_POST['show_metabox_admins']) ? true : false; $crp_settings['show_credit'] = isset($_POST['show_credit']) ? true : false; /**** Output options ****/ $crp_settings['title'] = wp_kses_post($_POST['title']); $crp_settings['blank_output'] = $_POST['blank_output'] == 'blank' ? true : false; $crp_settings['blank_output_text'] = wp_kses_post($_POST['blank_output_text']); $crp_settings['show_excerpt'] = isset($_POST['show_excerpt']) ? true : false; $crp_settings['show_date'] = isset($_POST['show_date']) ? true : false; $crp_settings['show_author'] = isset($_POST['show_author']) ? true : false; $crp_settings['excerpt_length'] = intval($_POST['excerpt_length']); $crp_settings['title_length'] = intval($_POST['title_length']); $crp_settings['link_new_window'] = isset($_POST['link_new_window']) ? true : false; $crp_settings['link_nofollow'] = isset($_POST['link_nofollow']) ? true : false; $crp_settings['before_list'] = wp_kses_post($_POST['before_list']); $crp_settings['after_list'] = wp_kses_post($_POST['after_list']); $crp_settings['before_list_item'] = wp_kses_post($_POST['before_list_item']); $crp_settings['after_list_item'] = wp_kses_post($_POST['after_list_item']); $crp_settings['exclude_on_post_ids'] = $_POST['exclude_on_post_ids'] == '' ? '' : implode(',', array_map('intval', explode(",", $_POST['exclude_on_post_ids']))); $crp_settings['exclude_post_ids'] = $_POST['exclude_post_ids'] == '' ? '' : implode(',', array_map('intval', explode(",", $_POST['exclude_post_ids']))); /**** Thumbnail options ****/ $crp_settings['post_thumb_op'] = wp_kses_post($_POST['post_thumb_op']); $crp_settings['thumb_size'] = $_POST['thumb_size']; if ('crp_thumbnail' != $crp_settings['thumb_size']) { $crp_thumb_size = crp_get_all_image_sizes($crp_settings['thumb_size']); $crp_settings['thumb_height'] = intval($crp_thumb_size['height']); $crp_settings['thumb_width'] = intval($crp_thumb_size['width']); $crp_settings['thumb_crop'] = $crp_thumb_size['crop']; } else { $crp_settings['thumb_height'] = intval($_POST['thumb_height']); $crp_settings['thumb_width'] = intval($_POST['thumb_width']); $crp_settings['thumb_crop'] = isset($_POST['thumb_crop']) ? true : false; } $crp_settings['thumb_html'] = $_POST['thumb_html']; $crp_settings['thumb_meta'] = '' == $_POST['thumb_meta'] ? 'post-image' : wp_kses_post($_POST['thumb_meta']); $crp_settings['scan_images'] = isset($_POST['scan_images']) ? true : false; $crp_settings['thumb_default'] = '' == $_POST['thumb_default'] || "/default.png" == $_POST['thumb_default'] ? $crp_url . '/default.png' : $_POST['thumb_default']; $crp_settings['thumb_default_show'] = isset($_POST['thumb_default_show']) ? true : false; /**** Feed options ****/ $crp_settings['limit_feed'] = intval($_POST['limit_feed']); $crp_settings['post_thumb_op_feed'] = wp_kses_post($_POST['post_thumb_op_feed']); $crp_settings['thumb_height_feed'] = intval($_POST['thumb_height_feed']); $crp_settings['thumb_width_feed'] = intval($_POST['thumb_width_feed']); $crp_settings['show_excerpt_feed'] = isset($_POST['show_excerpt_feed']) ? true : false; /**** Styles ****/ $crp_settings['custom_CSS'] = wp_kses_post($_POST['custom_CSS']); $crp_settings['crp_styles'] = wp_kses_post($_POST['crp_styles']); if ('rounded_thumbs' == $crp_settings['crp_styles']) { $crp_settings['include_default_style'] = true; $crp_settings['post_thumb_op'] = 'inline'; $crp_settings['show_excerpt'] = false; $crp_settings['show_author'] = false; $crp_settings['show_date'] = false; } elseif ('text_only' == $crp_settings['crp_styles']) { $crp_settings['include_default_style'] = false; $crp_settings['post_thumb_op'] = 'text_only'; } /**** Exclude categories ****/ $crp_settings['exclude_cat_slugs'] = wp_kses_post($_POST['exclude_cat_slugs']); $exclude_categories_slugs = explode(", ", $crp_settings['exclude_cat_slugs']); foreach ($exclude_categories_slugs as $exclude_categories_slug) { $catObj = get_category_by_slug($exclude_categories_slug); if (isset($catObj->term_id)) { $exclude_categories[] = $catObj->term_id; } } $crp_settings['exclude_categories'] = isset($exclude_categories) ? join(',', $exclude_categories) : ''; /**** Post types to include ****/ $wp_post_types = get_post_types(array('public' => true)); $post_types_arr = isset($_POST['post_types']) && is_array($_POST['post_types']) ? $_POST['post_types'] : array('post' => 'post'); $post_types = array_intersect($wp_post_types, $post_types_arr); $crp_settings['post_types'] = http_build_query($post_types, '', '&'); /**** Post types to exclude display on ****/ $post_types_excl_arr = isset($_POST['exclude_on_post_types']) && is_array($_POST['exclude_on_post_types']) ? $_POST['exclude_on_post_types'] : array(); $exclude_on_post_types = array_intersect($wp_post_types, $post_types_excl_arr); $crp_settings['exclude_on_post_types'] = http_build_query($exclude_on_post_types, '', '&'); /** * Filters $crp_settings before it is saved into the database * * @since 2.0.0 * * @param array $crp_settings CRP settings * @param array $_POST POST array that consists of the saved settings */ $crp_settings = apply_filters('crp_save_options', $crp_settings, $_POST); /**** Update CRP options into the database ****/ update_option('ald_crp_settings', $crp_settings); $crp_settings = crp_read_options(); parse_str($crp_settings['post_types'], $post_types); $posts_types_inc = array_intersect($wp_post_types, $post_types); parse_str($crp_settings['exclude_on_post_types'], $exclude_on_post_types); $posts_types_excl = array_intersect($wp_post_types, $exclude_on_post_types); // Delete the cache delete_post_meta_by_key('crp_related_posts'); delete_post_meta_by_key('crp_related_posts_widget'); delete_post_meta_by_key('crp_related_posts_feed'); delete_post_meta_by_key('crp_related_posts_widget_feed'); /* Echo a success message */ $str = '<div id="message" class="notice is-dismissible updated"><p>' . __('Options saved successfully.', CRP_LOCAL_NAME) . '</p>'; if ('rounded_thumbs' == $crp_settings['crp_styles']) { $str .= '<p>' . __('Rounded Thumbnails style selected. Author, Excerpt and Date will not be displayed.', CRP_LOCAL_NAME) . '</p>'; } if ('text_only' == $crp_settings['crp_styles']) { $str .= '<p>' . __('Text Only style selected. Thumbnails will not be displayed.', CRP_LOCAL_NAME) . '</p>'; } if ('crp_thumbnail' != $crp_settings['thumb_size']) { $str .= '<p>' . sprintf(__('Pre-built thumbnail size selected. Thumbnail set to %d x %d.', CRP_LOCAL_NAME), $crp_settings['thumb_width'], $crp_settings['thumb_height']) . '</p>'; } $str .= '</div>'; echo $str; } if (isset($_POST['crp_default']) && check_admin_referer('crp-plugin-settings')) { delete_option('ald_crp_settings'); $crp_settings = crp_default_options(); update_option('ald_crp_settings', $crp_settings); $crp_settings = crp_read_options(); $wp_post_types = get_post_types(array('public' => true)); parse_str($crp_settings['post_types'], $post_types); $posts_types_inc = array_intersect($wp_post_types, $post_types); parse_str($crp_settings['exclude_on_post_types'], $exclude_on_post_types); $posts_types_excl = array_intersect($wp_post_types, $exclude_on_post_types); $str = '<div id="message" class="updated fade"><p>' . __('Options set to Default.', CRP_LOCAL_NAME) . '</p></div>'; echo $str; } if (isset($_POST['crp_recreate']) && check_admin_referer('crp-plugin-settings')) { if ($wpdb->get_results("SHOW INDEX FROM {$wpdb->posts} where Key_name = 'crp_related'")) { $wpdb->query("ALTER TABLE " . $wpdb->posts . " DROP INDEX crp_related"); } if ($wpdb->get_results("SHOW INDEX FROM {$wpdb->posts} where Key_name = 'crp_related_title'")) { $wpdb->query("ALTER TABLE " . $wpdb->posts . " DROP INDEX crp_related_title"); } if ($wpdb->get_results("SHOW INDEX FROM {$wpdb->posts} where Key_name = 'crp_related_content'")) { $wpdb->query("ALTER TABLE " . $wpdb->posts . " DROP INDEX crp_related_content"); } crp_single_activate(); $str = '<div id="message" class="updated fade"><p>' . __('Index recreated', CRP_LOCAL_NAME) . '</p></div>'; echo $str; } /**** Include the views page ****/ include_once 'main-view.php'; }
/** * Function generates the plugin settings page. * * @since 1.0.1 * */ function crp_options() { global $wpdb; $crp_settings = crp_read_options(); $wp_post_types = get_post_types(array('public' => true)); parse_str($crp_settings['post_types'], $post_types); $posts_types_inc = array_intersect($wp_post_types, $post_types); parse_str($crp_settings['exclude_on_post_types'], $exclude_on_post_types); $posts_types_excl = array_intersect($wp_post_types, $exclude_on_post_types); if (isset($_POST['crp_save']) && check_admin_referer('crp-plugin-settings')) { /**** General options ***/ $crp_settings['cache'] = isset($_POST['cache']) ? true : false; $crp_settings['limit'] = intval($_POST['limit']); $crp_settings['daily_range'] = intval($_POST['daily_range']); $crp_settings['match_content'] = isset($_POST['match_content']) ? true : false; $crp_settings['match_content_words'] = intval($_POST['match_content_words']); $crp_settings['add_to_content'] = isset($_POST['add_to_content']) ? true : false; $crp_settings['add_to_page'] = isset($_POST['add_to_page']) ? true : false; $crp_settings['add_to_feed'] = isset($_POST['add_to_feed']) ? true : false; $crp_settings['add_to_home'] = isset($_POST['add_to_home']) ? true : false; $crp_settings['add_to_category_archives'] = isset($_POST['add_to_category_archives']) ? true : false; $crp_settings['add_to_tag_archives'] = isset($_POST['add_to_tag_archives']) ? true : false; $crp_settings['add_to_archives'] = isset($_POST['add_to_archives']) ? true : false; $crp_settings['content_filter_priority'] = intval($_POST['content_filter_priority']); $crp_settings['show_credit'] = isset($_POST['show_credit']) ? true : false; /**** Output options ****/ $crp_settings['title'] = wp_kses_post($_POST['title']); $crp_settings['blank_output'] = $_POST['blank_output'] == 'blank' ? true : false; $crp_settings['blank_output_text'] = wp_kses_post($_POST['blank_output_text']); $crp_settings['show_excerpt'] = isset($_POST['show_excerpt']) ? true : false; $crp_settings['show_date'] = isset($_POST['show_date']) ? true : false; $crp_settings['show_author'] = isset($_POST['show_author']) ? true : false; $crp_settings['excerpt_length'] = intval($_POST['excerpt_length']); $crp_settings['title_length'] = intval($_POST['title_length']); $crp_settings['link_new_window'] = isset($_POST['link_new_window']) ? true : false; $crp_settings['link_nofollow'] = isset($_POST['link_nofollow']) ? true : false; $crp_settings['before_list'] = wp_kses_post($_POST['before_list']); $crp_settings['after_list'] = wp_kses_post($_POST['after_list']); $crp_settings['before_list_item'] = wp_kses_post($_POST['before_list_item']); $crp_settings['after_list_item'] = wp_kses_post($_POST['after_list_item']); $crp_settings['exclude_on_post_ids'] = $_POST['exclude_on_post_ids'] == '' ? '' : implode(',', array_map('intval', explode(",", $_POST['exclude_on_post_ids']))); $crp_settings['exclude_post_ids'] = $_POST['exclude_post_ids'] == '' ? '' : implode(',', array_map('intval', explode(",", $_POST['exclude_post_ids']))); $crp_settings['post_thumb_op'] = wp_kses_post($_POST['post_thumb_op']); $crp_settings['thumb_height'] = intval($_POST['thumb_height']); $crp_settings['thumb_width'] = intval($_POST['thumb_width']); $crp_settings['thumb_crop'] = isset($_POST['thumb_crop']) ? true : false; $crp_settings['thumb_html'] = $_POST['thumb_html']; $crp_settings['thumb_meta'] = '' == $_POST['thumb_meta'] ? 'post-image' : wp_kses_post($_POST['thumb_meta']); $crp_settings['scan_images'] = isset($_POST['scan_images']) ? true : false; $crp_settings['thumb_default'] = wp_kses_post($_POST['thumb_default']); $crp_settings['thumb_default_show'] = isset($_POST['thumb_default_show']) ? true : false; $crp_settings['thumb_timthumb'] = isset($_POST['thumb_timthumb']) ? true : false; $crp_settings['thumb_timthumb_q'] = intval($_POST['thumb_timthumb_q']); /**** Feed options ****/ $crp_settings['limit_feed'] = intval($_POST['limit_feed']); $crp_settings['post_thumb_op_feed'] = wp_kses_post($_POST['post_thumb_op_feed']); $crp_settings['thumb_height_feed'] = intval($_POST['thumb_height_feed']); $crp_settings['thumb_width_feed'] = intval($_POST['thumb_width_feed']); $crp_settings['show_excerpt_feed'] = isset($_POST['show_excerpt_feed']) ? true : false; /**** Custom styles ****/ $crp_settings['custom_CSS'] = wp_kses_post($_POST['custom_CSS']); if (isset($_POST['include_default_style'])) { $crp_settings['include_default_style'] = true; $crp_settings['post_thumb_op'] = 'inline'; $crp_settings['thumb_height'] = 150; $crp_settings['thumb_width'] = 150; $crp_settings['show_excerpt'] = false; $crp_settings['show_author'] = false; $crp_settings['show_date'] = false; } else { $crp_settings['include_default_style'] = false; } /**** Exclude categories ****/ $crp_settings['exclude_cat_slugs'] = wp_kses_post($_POST['exclude_cat_slugs']); $exclude_categories_slugs = explode(", ", $crp_settings['exclude_cat_slugs']); foreach ($exclude_categories_slugs as $exclude_categories_slug) { $catObj = get_category_by_slug($exclude_categories_slug); if (isset($catObj->term_id)) { $exclude_categories[] = $catObj->term_id; } } $crp_settings['exclude_categories'] = isset($exclude_categories) ? join(',', $exclude_categories) : ''; /**** Post types to include ****/ $wp_post_types = get_post_types(array('public' => true)); $post_types_arr = isset($_POST['post_types']) && is_array($_POST['post_types']) ? $_POST['post_types'] : array('post' => 'post'); $post_types = array_intersect($wp_post_types, $post_types_arr); $crp_settings['post_types'] = http_build_query($post_types, '', '&'); /**** Post types to exclude display on ****/ $post_types_excl_arr = isset($_POST['exclude_on_post_types']) && is_array($_POST['exclude_on_post_types']) ? $_POST['exclude_on_post_types'] : array(); $exclude_on_post_types = array_intersect($wp_post_types, $post_types_excl_arr); $crp_settings['exclude_on_post_types'] = http_build_query($exclude_on_post_types, '', '&'); /** * Filters $crp_settings before it is saved into the database * * @param array $crp_settings CRP settings * @param array $_POST POST array that consists of the saved settings */ $crp_settings = apply_filters('crp_save_options', $crp_settings, $_POST); /**** Update CRP options into the database ****/ update_option('ald_crp_settings', $crp_settings); $crp_settings = crp_read_options(); parse_str($crp_settings['post_types'], $post_types); $posts_types_inc = array_intersect($wp_post_types, $post_types); parse_str($crp_settings['exclude_on_post_types'], $exclude_on_post_types); $posts_types_excl = array_intersect($wp_post_types, $exclude_on_post_types); delete_post_meta_by_key('crp_related_posts'); // Delete the cache delete_post_meta_by_key('crp_related_posts_widget'); // Delete the cache $str = '<div id="message" class="updated fade"><p>' . __('Options saved successfully.', CRP_LOCAL_NAME) . '</p></div>'; echo $str; } if (isset($_POST['crp_default']) && check_admin_referer('crp-plugin-settings')) { delete_option('ald_crp_settings'); $crp_settings = crp_default_options(); update_option('ald_crp_settings', $crp_settings); $crp_settings = crp_read_options(); $wp_post_types = get_post_types(array('public' => true)); parse_str($crp_settings['post_types'], $post_types); $posts_types_inc = array_intersect($wp_post_types, $post_types); parse_str($crp_settings['exclude_on_post_types'], $exclude_on_post_types); $posts_types_excl = array_intersect($wp_post_types, $exclude_on_post_types); $str = '<div id="message" class="updated fade"><p>' . __('Options set to Default.', CRP_LOCAL_NAME) . '</p></div>'; echo $str; } if (isset($_POST['crp_recreate']) && check_admin_referer('crp-plugin-settings')) { $wpdb->query("ALTER TABLE " . $wpdb->posts . " DROP INDEX crp_related"); $wpdb->query("ALTER TABLE " . $wpdb->posts . " DROP INDEX crp_related_title"); $wpdb->query("ALTER TABLE " . $wpdb->posts . " DROP INDEX crp_related_content"); crp_single_activate(); $str = '<div id="message" class="updated fade"><p>' . __('Index recreated', CRP_LOCAL_NAME) . '</p></div>'; echo $str; } /**** Include the views page ****/ include_once 'main-view.php'; }