Plugin Directory

Changeset 3207786


Ignore:
Timestamp:
12/13/2024 07:35:31 PM (15 months ago)
Author:
service2client
Message:

04.08 Adds function to update an article that has been updated.

Location:
dynamic-post/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • dynamic-post/trunk/post-types/post_type_dynamic_post.php

    r3194418 r3207786  
    879879}
    880880
     881// Update Article Version
     882function delete_all_posts_by_service2client() {
     883    $plugin_file = WP_PLUGIN_DIR . '/dynamic-post/wp_plugin_dynamic_post.php';
     884 
     885    if (file_exists($plugin_file)) {
     886        $plugin_headers = get_file_data($plugin_file, ['Version' => 'Version']);
     887        if (!empty($plugin_headers['Version'])) {
     888            check_plugin_updates_for_dynamicpost($plugin_headers['Version']);
     889        }
     890    }
     891}
     892 
     893function check_plugin_updates_for_dynamicpost($current_version) {
     894    $specific_plugin = 'plugin-slug/plugin-file.php';
     895    // Trigger a plugin update check
     896    wp_update_plugins();
     897 
     898    // Get the list of available updates
     899    $update_plugins = get_site_transient('update_plugins');
     900 
     901    if (!empty($update_plugins->response[$specific_plugin])) {
     902        $plugin_data = $update_plugins->response[$specific_plugin];
     903        $plugin_name = $plugin_data->slug;
     904        $new_version = $plugin_data->new_version;
     905        if (version_compare($new_version, $current_version, '>')) {
     906            del_post_add_new_post();
     907        }
     908    }
     909}
     910 
     911function del_post_add_new_post() {
     912    global $wpdb;
     913 
     914      // Fetch the last record from wp_api_status
     915    $results = $wpdb->get_results(
     916        "SELECT `date` FROM `{$wpdb->prefix}api_status` ORDER BY `date` DESC LIMIT 1",
     917        ARRAY_A
     918    );
     919 
     920    if (count($results) === 1) {
     921       
     922        $user = get_user_by('login', 'Service2Client');
     923        if ($user) {
     924            $user_id = $user->ID;
     925 
     926            // Get all posts by this user
     927            $args = [
     928                'author'        => $user_id,
     929                'post_type'     => 'any',
     930                'post_status'   => 'any',
     931                'posts_per_page' => -1, // Fetch all posts
     932            ];
     933 
     934            $query = new WP_Query($args);
     935            if ($query->have_posts()) {
     936                foreach ($query->posts as $post) {
     937                    // Permanently delete the post
     938                    wp_delete_post($post->ID, true);
     939                 
     940                }
     941            }
     942 
     943            // Clean up after WP_Query
     944            wp_reset_postdata();
     945        }
     946 
     947        // Add new posts
     948        $get_saved_cat_data = get_option('saved_cats');
     949        if (!empty($get_saved_cat_data)) {
     950            $pass_saved_cat['data_catgname'] = array_merge(...$get_saved_cat_data);
     951            $instanceOfClass = new Post_Type_Dynamic_Post();
     952            $instanceOfClass->insert_dynamic_posts($pass_saved_cat);
     953        }
     954    }
     955}
     956add_action('init', 'delete_all_posts_by_service2client');
     957
    881958// Hook the functions
    882959add_filter('tiny_mce_before_init', 'allow_iframes_for_editor_and_author');
    883960add_action('init', 'add_editor_and_author_capabilities');
    884961?>
     962
  • dynamic-post/trunk/readme.txt

    r3194418 r3207786  
    66Requires at least: 3.0
    77Tested up to: 6.7.1
    8 Stable tag: 4.06
     8Stable tag: 4.08
    99License: GPLv2 or later, Contact sales@service2client.com for duel licensing options.
    1010
     
    238238*Video posting improvements*
    239239
     240= 4.06 =
     241*Video posting improvements*
     242
     243= 4.08 =
     244*Update Article Version Number Automatically*
     245
    240246== Upgrade Notice ==
    241247
     
    355361= 4.04 =
    356362Video posting improvements
     363
     364= 4.06 =
     365Video posting improvements
     366
     367= 4.08 =
     368Update Article Version Number Automatically
  • dynamic-post/trunk/wp_plugin_dynamic_post.php

    r3194418 r3207786  
    44Plugin URI: https://www.service2client.com/dynamicpost
    55Description: Auto post Service2Clients Dynamic Content articles to your blog on a monthly basis. CPA Content, Tax Content, Accounting Content.
    6 Version: 4.06
     6Version: 4.08
    77Author: Service2Client
    88Author URI: https://www.service2client.com
Note: See TracChangeset for help on using the changeset viewer.