0

I have a lot of functions in my functions.php and need to call them directly inside functions.php. I did this in this way but admin panel started to work very slowly when am calling functions in this way:

function setTumblrShares($tumblrUrl){  
    global $wpdb; 
    $shareTmbArgs = array(
       'posts_per_page' => -1,
       'offset' => 0,
       'order' => 'DESC',
       'orderby'  => 'date',
       'post_type' => 'video', 
       'post_status' => 'publish',
       'suppress_filters' => 0 
   );
   $shareTumblrCountList = get_posts($shareTmbArgs);
   if ($shareTumblrCountList) {
      foreach ($shareTumblrCountList as $shareTumblrCountItem) {
        $tumblrUrl = get_permalink($shareTumblrCountItem->ID); 
        $shareTumbData = getTumblrShares($tumblrUrl);
        $tumblrShares = $shareTumbData["response"]["note_count"]; 
        $table_name = $wpdb->prefix . "posts";
        $wpdb->update( $table_name, array( 'tumblrShareCount' => $tumblrShares),array('ID'=>$shareTumblrCountItem->ID));
      } 
   }
}
function getTumblrShares($tumblrUrl){  
   $jsonForReddit =  json_decode(file_get_contents("http://api.tumblr.com/v2/share/stats?url=".$tumblrUrl),true);
   return $jsonForReddit;
} 
add_action('admin_menu', 'setTumblrShares'); 
17
  • Effect of WP speed depends on what you called in myFunction. Commented Oct 13, 2015 at 6:30
  • I updated my question, see it now pls @Raptor Commented Oct 13, 2015 at 6:31
  • Try pre_get_posts , not tested but still believes it may help you. Commented Oct 13, 2015 at 6:38
  • I tried but it gives me an error FATAL ERROR: ALLOWED MEMORY SIZE OF 268435456 BYTES EXHAUSTED (TRIED TO ALLOCATE 523800 BYTES) IN /WP-INCLUDES/QUERY.PHP ON LINE 2389 @PrafullaKumarSahu Commented Oct 13, 2015 at 6:41
  • If memory size is the problem, you can increase the size from php.ini file.but can you describe what you are trying to achieve, I do not want to understand it from your code. Commented Oct 13, 2015 at 6:44

2 Answers 2

1

If you want to call some function inside your functions.php use the related hook or visit actions and filters and also consider checking your templates and find which hook should be used for calling which functions , you if want to modify the output use filter and if you want to perform some action use action.Depending open the job you need to use the hooks.

Sign up to request clarification or add additional context in comments.

Comments

0

Use admin_init

add_action('admin_init', 'setTumblrShares'); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.