Created
June 7, 2018 13:15
-
-
Save Inzman/a3965a5bdca3a18528c8869d51da7a07 to your computer and use it in GitHub Desktop.
Replace stuff in content
This file contains hidden or 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 | |
| if(is_user_logged_in()){ | |
| $args = array( | |
| 'sort_order' => 'asc', | |
| 'sort_column' => 'post_title', | |
| 'post_type' => 'page', | |
| 'numberposts' => -1, | |
| 'post_status' => 'any', | |
| 'suppress_filters' => true | |
| ); | |
| $pages = get_posts($args); | |
| echo '<table>'; | |
| foreach($pages as $page){ //pre($page); | |
| $nr = $_GET['nr']; | |
| $string_to_look_for = "[$nr]"; | |
| $replace_with = '<a href="#viited"><sup>'.$nr.'</sup></a>'; | |
| //$string_to_look_for = '<a href="#_ftn19" name="_ftnref19">[19]</a>'; | |
| //$replace_with = '<a href="#viited" name="_ftnref19">19</a>'; | |
| //$string_to_look_for = '<sup><a href="#viited"><sup>1</sup></a></sup>'; | |
| //$replace_with = '<a href="#viited"><sup>1</sup></a>'; | |
| $original_content = $page->post_content; | |
| $new_content = (substr_count($original_content, $string_to_look_for) > 0) ? str_replace($string_to_look_for, $replace_with, $original_content) : $original_content; | |
| $warning = (substr_count($original_content, $string_to_look_for) > 0) ? 'style="background:pink;"': ''; | |
| if(substr_count($original_content, $string_to_look_for) > 0){ | |
| echo '<tr '.$warning.'><td style="padding:10px;"><a href="'.str_replace('palm', 'kairi', get_permalink($page->ID)).'" target="_blank" style="color:#000;text-decoration:underline">'.$page->post_title.'</a></td><td style="padding:10px;">'.wp_trim_words(apply_filters('the_content', $original_content)).'</td><td style="padding:10px;">'.wp_trim_words(apply_filters('the_content', $new_content)).'</td></tr>'; | |
| $my_post = array( | |
| 'ID' => $page->ID, | |
| 'post_content' => $new_content | |
| ); | |
| if(isset($_GET['update'])) wp_update_post($my_post); | |
| } | |
| /* | |
| $widgets = get_field('widgets', $page->ID); | |
| if($widgets && is_array($widgets)){ //pre($widgets); | |
| foreach($widgets as $widget){ | |
| if($widget['acf_fc_layout'] == 'viited' ){ | |
| //if(!empty($widget['viited_sisu'])){ | |
| //echo '<tr><td style="padding:10px;"><a href="'.str_replace('palm', 'kairi', get_permalink($page->ID)).'" target="_blank">'.$page->post_title.'</a></td><td>'.$widget['viited_sisu'].'</td></tr>'; | |
| //} | |
| } | |
| } | |
| } else { | |
| //echo '<tr style="background:pink;"><td style="padding:10px;"><a href="'.str_replace('palm', 'kairi', get_permalink($page->ID)).'" target="_blank">'.$page->post_title.'</a></td><td></td></tr>'; | |
| } | |
| */ | |
| } | |
| echo '</table>'; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment