Ejemplo n.º 1
0
/**
 * Changes the state of feed sources selected from the table bulk actions.
 * 
 * @since 4.1
 */
function wprss_bulk_change_state()
{
    // If the id and state are in POST data
    if (isset($_GET['post_type']) && (isset($_GET['action']) || isset($_GET['action2'])) && isset($_GET['post'])) {
        // Get the action and post ids from GET request
        $action = isset($_GET['action']) && $_GET['action'] !== '-1' ? $_GET['action'] : $_GET['action2'];
        $post_ids = $_GET['post'];
        // check the action
        switch ($action) {
            // Activate all feed sources in $post_ids
            case 'activate':
                foreach ($post_ids as $post_id) {
                    wprss_activate_feed_source($post_id);
                }
                // Set a transient to show the admin notice, after redirection
                set_transient('wprss_notify_bulk_change_state', 'activated', 0);
                break;
                // Pause all feed sources in $post_ids
            // Pause all feed sources in $post_ids
            case 'pause':
                foreach ($post_ids as $post_id) {
                    wprss_pause_feed_source($post_id);
                }
                // Set a transient to show the admin notice, after redirection
                set_transient('wprss_notify_bulk_change_state', 'paused', 0);
                break;
        }
        /* Note:
         * Transients are used since bulk actions will, after processing, case a redirect to the same page.
         * Thus, using add_action( 'all_admin_notices', ... ) will result in the notice appearing on the first request,
         * and not be shown after redirection.
         * The transient is set to show the notification AFTER redirection.
         */
    }
}
Ejemplo n.º 2
0
/**     
 * Save the custom fields
 * 
 * @since 2.0
 */
function wprss_save_custom_fields($post_id, $post)
{
    $meta_fields = wprss_get_custom_fields();
    /* Verify the nonce before proceeding. */
    if (!isset($_POST['wprss_meta_box_nonce']) || !wp_verify_nonce($_POST['wprss_meta_box_nonce'], basename(__FILE__))) {
        return $post_id;
    }
    /* Get the post type object. */
    $post_type = get_post_type_object($post->post_type);
    /* Check if the current user has permission to edit the post. */
    if (!current_user_can($post_type->cap->edit_post, $post_id)) {
        return $post_id;
    }
    /*  // Stop WP from clearing custom fields on autosave - maybe not needed
            if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
                return;
    
            // Prevent quick edit from clearing custom fields - maybe not needed
            if (defined('DOING_AJAX') && DOING_AJAX)
                return;     */
    /** Bail out if running an autosave, ajax or a cron */
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if (defined('DOING_AJAX') && DOING_AJAX) {
        return;
    }
    if (defined('DOING_CRON') && DOING_CRON) {
        return;
    }
    // Change the limit, if it is zero, to an empty string
    if (isset($_POST['wprss_limit']) && strval($_POST['wprss_limit']) == '0') {
        $_POST['wprss_limit'] = '';
    }
    // loop through fields and save the data
    foreach ($meta_fields as $field) {
        $old = get_post_meta($post_id, $field['id'], true);
        $new = trim($_POST[$field['id']]);
        if ($new && $new != $old) {
            update_post_meta($post_id, $field['id'], $new);
        } elseif ('' == $new && $old) {
            delete_post_meta($post_id, $field['id'], $old);
        }
    }
    // end foreach
    $force_feed = isset($_POST['wprss_force_feed']) ? $_POST['wprss_force_feed'] : 'false';
    $state = isset($_POST['wprss_state']) ? $_POST['wprss_state'] : 'active';
    $activate = isset($_POST['wprss_activate_feed']) ? stripslashes($_POST['wprss_activate_feed']) : '';
    $pause = isset($_POST['wprss_pause_feed']) ? stripslashes($_POST['wprss_pause_feed']) : '';
    $age_limit = isset($_POST['wprss_age_limit']) ? stripslashes($_POST['wprss_age_limit']) : '';
    $age_unit = isset($_POST['wprss_age_unit']) ? stripslashes($_POST['wprss_age_unit']) : '';
    $update_interval = isset($_POST['wprss_update_interval']) ? stripslashes($_POST['wprss_update_interval']) : wprss_get_default_feed_source_update_interval();
    $old_update_interval = get_post_meta($post_id, 'wprss_update_interval', TRUE);
    // Update the feed source meta
    update_post_meta($post_id, 'wprss_force_feed', $force_feed);
    update_post_meta($post_id, 'wprss_activate_feed', $activate);
    update_post_meta($post_id, 'wprss_pause_feed', $pause);
    update_post_meta($post_id, 'wprss_age_limit', $age_limit);
    update_post_meta($post_id, 'wprss_age_unit', $age_unit);
    update_post_meta($post_id, 'wprss_update_interval', $update_interval);
    // Check if the state or the update interval has changed
    if (get_post_meta($post_id, 'wprss_state', TRUE) !== $state || $old_update_interval !== $update_interval) {
        // Pause the feed source, and if it is active, re-activate it.
        // This should update the feed's scheduling
        wprss_pause_feed_source($post_id);
        if ($state === 'active') {
            wprss_activate_feed_source($post_id);
        }
    }
    // Update the schedules
    wprss_update_feed_processing_schedules($post_id);
    // If the feed source uses the global updating system, update the feed on publish
    if ($update_interval === wprss_get_default_feed_source_update_interval()) {
        wp_schedule_single_event(time(), 'wprss_fetch_single_feed_hook', array($post_id));
    }
}