Advertisement
terorama

WP / tests5

Mar 29th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.64 KB | None | 0 0
  1.  
  2. <?php
  3.  
  4. //-------------------------------------------------
  5. define('WP_USE_THEMES', false);
  6. require('../wp-load.php');
  7.  
  8. header('Content-type: text/html; charset=utf-8');
  9. //-------------------------------------------------
  10.  
  11. ?>
  12.  
  13. <style type="text/css">
  14.    div {
  15.       float:left;
  16.       margin-right:10px;
  17.    }
  18. </style>
  19.  
  20.  
  21. <?php
  22.  
  23. //post_info();
  24. //diff();
  25.  
  26. //mk_cats4();
  27. mk_post();
  28.  
  29. //-------------------------------------------------
  30. function mk_post() {
  31.  
  32. $my_post = array(
  33.   'post_title'    => 'test auto post',
  34.   'post_content'  =>
  35.     'Lorem ipsum dolor sit amet, consectetur adipiscing elit. '.
  36.     'Etiam id tortor lacus. Donec sapien nisl, '.
  37.     'tincidunt sed sollicitudin nec, dictum nec quam. ',
  38.  
  39.   'post_status'   => 'publish',
  40.   'post_author'   => 1,
  41.   'post_category' => array(4)
  42. );
  43.  
  44. // Insert the post into the database
  45. wp_insert_post( $my_post );
  46.    
  47. }
  48.  
  49.  
  50. //-------------------------------------------------
  51. function mk_cats4() {
  52.  
  53.    $args =  array(
  54.         'name'=> 'test base 7 category',      
  55.         'description'=>'test inserting category',
  56.         'slug'=>sanitize_title('test base 7 category'),
  57.         'parent'=>''
  58.        );
  59.  
  60.    $inf = get_category(16, ARRAY_A);
  61.  
  62.    //if (term_exists('test base 7 -category'))
  63.    // get_term($term_id, $taxonomy);
  64.  
  65.    if (!$inf)
  66.       wp_insert_term('test base 7 -category', 'category', $args);
  67.    else
  68.       wp_update_term(16, 'category', $args);
  69.  
  70.    foreach (array(11,12,13,14,15,17,18) as $num) {
  71.       $inf = get_category($num, ARRAY_A);
  72.       if ($inf) {
  73.          wp_delete_term($num, 'category');
  74.       }
  75.    }
  76. }
  77.  
  78. //-------------------------------------------------
  79. function mk_cats() {
  80.  
  81.   require_once(ABSPATH . "wp-admin/includes/taxonomy.php");
  82.  
  83.   $my_cat = array(
  84.      'cat_ID' =>11,
  85.      'cat_name' => 'test base 4 category',
  86.      'category_description' => 'A Cool Category',
  87.      'category_nicename' => 'testcategory4-slug',
  88.      'category_parent' => '');
  89.  
  90.  
  91.  
  92.    $my_cat_id = wp_insert_category($my_cat);
  93.    echo $my_cat_id;
  94.  
  95. }
  96.  
  97.  
  98.  
  99. //-------------------------------------------------
  100. function post_info() {
  101.  
  102.  $args = array('post_type'=>'post');
  103.    $q = new WP_Query($args);
  104.    
  105.    while ($q->have_posts()) {
  106.       $q->the_post();
  107.       echo '<br/><br/>';
  108.       the_id();echo ' ';the_title();echo ' '; the_date(); echo ' ';the_author(); echo '<br/>';
  109.       echo 'post_format='.get_post_format(get_the_id()).'<br/>';
  110.  
  111.       $cats = get_the_category(get_the_id());
  112.  
  113.       if ($cats) {
  114.          echo '<br/>categories:<br/><br/>';
  115.          foreach ($cats as $cat) {
  116.             //echo '<pre>'.print_r($cat, true).'</pre>';
  117.             echo 'category='.$cat->name.'<br/>';
  118.             echo 'cat_term_id='.$cat->term_id.'<br/>';
  119.             echo 'cat_link='.get_category_link($cat->term_id).'<br/>';
  120.             echo 'cat_desc='.$cat->description.'<br/>';
  121.             echo 'cat_slug='.$cat->slug.'<br/>';
  122.             echo 'cat_id='.$cat->cat_ID.'<br/>';
  123.             echo 'cat_name='.$cat->cat_name.'<br/>';
  124.             echo 'cat_parent='.$cat->category_parent.'<br/>';
  125.  
  126.             echo  'cat_parents='.get_category_parents($cat->cat_ID, false, ',').'<br/>';
  127.          }
  128.       }
  129.      
  130.       $tags = get_the_tags(get_the_id());
  131.       if ($tags) {
  132.          echo '<br/>tags<br/><br/>';
  133.          foreach ($tags as $tag) {
  134.              //echo '<pre>'.print_r($tag, true).'</pre>';
  135.              echo 'tag_id='.$tag->term_id.'<br/>';
  136.              echo 'tag_name='.$tag->name.'<br/>';
  137.              echo 'tag_slug='.$tag->slug.'<br/>';
  138.              echo 'tag_desc='.$tag->description.'<br/>';
  139.              echo 'tag_parent='.$tag->parent.'<br/>';
  140.  
  141.              echo 'tag_link='.get_tag_link($tag->term_id).'<br/><br/>';
  142.  
  143.          }
  144.       }
  145.  
  146.       $taxonomies = get_the_taxonomies(get_the_id());
  147.  
  148.       if ($taxonomies) {
  149.  
  150.          echo '<br/>taxonomies<br/><br/>';
  151.        
  152.          foreach ($taxonomies as $taxo) {
  153.             echo $taxo.'<br/>';
  154.          }
  155.       }
  156.      
  157.       //    the_category();
  158.       //    the_tags();
  159.       //    the_taxonomies();
  160.       //    the_terms(get_the_id(),'category');
  161.  
  162.    }
  163.  
  164.  
  165. }
  166.  
  167. //-------------------------------------------------
  168. function diff() {
  169.    
  170.   wp_tag_cloud();
  171.  
  172.   echo '<br/><br/>';
  173.   wp_list_categories();
  174.  
  175.   echo '<br/><br/>';
  176.   echo '<pre>'.print_r(get_the_taxonomies(), true).'</pre>';
  177.  
  178.   echo '<br/><br/>';
  179.  
  180.    $tags = get_tags();
  181.    $html = '<div class="post_tags">';
  182.  
  183.    foreach ( $tags as $tag ) {
  184.  
  185.     $tag_link = get_tag_link( $tag->term_id );
  186.            
  187.     $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
  188.     $html .= "{$tag->name}</a>";
  189.     }
  190.     $html .= '</div>';
  191.     echo $html;
  192. }
  193.  
  194. //-------------------------------------------------
  195. function get_meta() {
  196.  
  197.    $args = array('post_type'=>'post');
  198.    $q = new WP_Query($args);
  199.    
  200.    while ($q->have_posts()) {
  201.       $q->the_post();
  202.      
  203.       the_id();echo ' ';the_title();echo ' '; the_date(); echo ' ';the_author(); echo '<br/>';
  204.  
  205.       $mt = get_post_meta(get_the_id() );
  206.  
  207.       echo '<pre>'.print_r($mt, true).'</pre>';
  208.       //echo implode('<br/>',array_keys($mt)).'<br/>';
  209.  
  210.    }
  211. }
  212. //-------------------------------------------------
  213. function get_info4() {
  214.  
  215.    echo '<div><h3>post types</h3>';
  216.  
  217.    $post_types=get_post_types('','objects');
  218.  
  219.    foreach ($post_types as $p ) {
  220.       echo 'name='.$p->name.'<br/>';
  221.       echo 'label='.$p->label.'<br/>';
  222.       echo 'description='.$p->description.'<br/>';
  223.       echo 'labels[name]='.$p->labels->name.'<br/>';
  224.       echo 'edit_link='.$p->_edit_link.'<br/>';
  225.       echo str_repeat('-',50).'<br/>';
  226.    }
  227.    echo '</div>';
  228.  
  229.    
  230.  
  231. }
  232.  
  233. ?>
  234.  
  235. <?php
  236.  
  237. //-------------------------------------------------
  238. define('WP_USE_THEMES', false);
  239. require('../wp-load.php');
  240. header('Content-type: text/html; charset=utf-8');
  241. //-------------------------------------------------
  242.  
  243. upd_comms();
  244.  
  245. //-------------------------------------------------
  246. function check_atts() {
  247.  
  248.    $args = array('post_type'=>'post', 'post_status'=>'published');
  249.  
  250.    $que = new WP_Query($args);
  251.  
  252.    while ($que->have_posts()) {
  253.  
  254.       $que->the_post();
  255.      
  256.       $attachments =
  257.         get_children( array('post_parent' => get_the_ID(),
  258.            'post_type' => 'attachment',
  259.            'post_mime_type' => 'image') );
  260.  
  261.        if ( $attachments ) {
  262.          echo '<br/>'; the_ID(); echo ' - ';the_title(); echo '<br/>';
  263.  
  264.        
  265.            foreach ($attachments as $att) {
  266.            
  267.               echo print_r(wp_get_attachment_image_src( $att->ID, 'full' ),true).'<br/>';
  268.            }
  269.        }
  270.    }
  271. }
  272. //-------------------------------------------------
  273. function trim4($a) {
  274.    return substr($a,0,3);
  275. }
  276. //--------------------------
  277.  
  278. function upd_comms() {
  279.  
  280.    $comments = get_comments();
  281.  
  282.    echo '<h3>empty comments</h3>';
  283.  
  284.    foreach ($comments as $c) {
  285.       if (trim($c->comment_content, "\r\n\t\0 ")=='') {
  286.          echo $c->comment_ID.' '.$c->comment_author.' '.$c->comment_author_url.'<br/>';
  287.       }
  288.    }
  289.  
  290.    
  291. }
  292.  
  293. //--------------------------
  294. function upd_commsu() {
  295. $args = array(
  296.  
  297.        
  298.         'order'=>'DESC'
  299.        
  300. );
  301. $comments = get_comments($args);
  302.  
  303. echo '<ul>';
  304.  
  305. foreach($comments as $c) :
  306.  
  307.   $comm = get_comment( $c->comment_ID, ARRAY_A);
  308.  
  309.   echo '<li>';
  310.  
  311.   if (count(explode(' ', $comm['comment_author']))>1) {
  312.      echo 'test'.'<br/>';
  313.      $s = $comm['comment_author'];
  314.      $comm['comment_author']=implode(array_filter(array_map('trim4', explode(' ',ucwords(strtr($s, '-_/\+-=','       '))))));
  315.      wp_update_comment($comm);
  316.      }
  317.  
  318.  
  319.  
  320.    
  321. endforeach;
  322.  
  323. echo '</ul>';
  324. }
  325.  
  326.  
  327. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement