-
-
Save salcode/2baa7ee48a2b604a235b to your computer and use it in GitHub Desktop.
Example Iron-Ajax Usage. This file goes in mu-plugins and generates /wp-content/seo-spec-sheet-export.csv with the exported information.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Export old spec sheet Permalinks and slug for SEO population on new site | |
* 2014-12-15 | |
*/ | |
add_action( 'plugins_loaded', array( 'Fe_Export_Seo', 'init' ) ); | |
class Fe_Export_Seo { | |
public static function init() { | |
if ( class_exists( 'Fe_Ajx' ) ) { | |
new Fe_Ajx( array( | |
'instance_id' => 'Export SEO Links', | |
) ); | |
} | |
add_filter( 'fe_ajx_export_seo_links_entries_count', | |
array( __CLASS__, 'entries_count') | |
); | |
add_filter( 'fe_ajx_export_seo_links_process', | |
array( __CLASS__, 'process'), | |
10, | |
2 | |
); | |
} | |
public static function entries_count( $count ) { | |
$output_line = array( | |
'post_id', | |
'Permalink', | |
); | |
self::write_to_csv( $output_line ); | |
$args = self::get_query_args(); | |
$fe_query = new WP_Query( $args ); | |
$count = $fe_query->found_posts; | |
wp_reset_postdata(); | |
return $count; | |
} | |
public static function process( $result, $index ) { | |
$output_line = array(); | |
$args = self::get_query_args(); | |
$args['offset'] = $index; | |
$fe_query = new WP_Query( $args ); | |
if ( $fe_query->have_posts() ) { | |
$fe_query->the_post(); | |
$permalink = get_the_permalink(); | |
$output_line = array( | |
get_the_ID(), | |
$permalink, | |
); | |
self::write_to_csv( $output_line ); | |
} | |
wp_reset_postdata(); | |
return $result; | |
} | |
public static function write_to_csv( $line ) { | |
$fp = fopen( WP_CONTENT_DIR . '/seo-spec-sheet-export.csv', 'a' ); | |
fputcsv( $fp, $line ); | |
fclose( $fp ); | |
} | |
public static function get_query_args() { | |
return array( | |
'posts_per_page' => 1, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment