Last active
May 24, 2017 20:05
-
-
Save bryan3561/e794f534e03b0c8edff28452b3a99acc to your computer and use it in GitHub Desktop.
Revisions
-
bryan3561 revised this gist
May 24, 2017 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -60,3 +60,13 @@ function bkc_meta_views_shares( $post_id = null ) { return json_decode( json_encode( $post_meta ), false ); } } /* * Usos * var_dump(bkc_meta_views_shares()); * var_dump(bkc_meta_views_shares()->view_count); * var_dump(bkc_meta_views_shares()->shares); */ -
bryan3561 revised this gist
May 24, 2017 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,8 @@ function bkc_meta_views_shares( $post_id = null ) { } if (isset($posts_metas[$post_id])) return json_decode( json_encode( $posts_metas[$post_id] ), false ); /* * Extraer los datos desde mashared -
bryan3561 created this gist
May 24, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ <?php if ( ! function_exists( 'bkc_meta_views_shares' ) ) { function bkc_meta_views_shares( $post_id = null ) { $post_meta = []; static $posts_metas = []; /* * Si el ID no fue pasado, se asigna automaticamente el del post * que esta siendo leido en el momento donde se uso la funcion. */ if ( is_null( $post_id ) ) { global $post; $post_id = $post->ID; } if (isset($posts_metas[$post_id])) return $posts_metas[$post_id]; /* * Extraer los datos desde mashared */ $view_count_tmp = (int) get_post_meta( $post_id, '_mts_view_count', true ); $shares_tmp = (int) get_post_meta( $post_id, 'mashsb_shares', true ); /* * Si no tienen un valor los datos, se inician en 0 */ $post_meta['view_count'] = ( $view_count_tmp ) ? $view_count_tmp : 0; $post_meta['shares'] = ( $shares_tmp ) ? $shares_tmp : 0; /* * Numero inicial adicional a compartidas y visitas reales */ $getFakecount = getFakecount(); $porcentaje_adicional = 0; if ( $getFakecount > 0 ) { $porcentaje_adicional = round( ( $getFakecount * 50 ) / 100 ); } if ( $post_meta['view_count'] === 0 ) { $post_meta['view_count'] = $getFakecount + $porcentaje_adicional; } else { $post_meta['view_count'] = $post_meta['view_count'] + $getFakecount + $porcentaje_adicional; } if ( $post_meta['shares'] === 0 ) { $post_meta['shares'] = $getFakecount; } else { $post_meta['shares'] = $post_meta['shares'] + $getFakecount; } $post_meta['shares'] = round( $post_meta['shares'] ); $post_meta['view_count'] = round( $post_meta['view_count'] ); $posts_metas[$post_id] = $post_meta; return json_decode( json_encode( $post_meta ), false ); } }