| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) |
| 3 |
exit; |
| 4 |
|
| 5 |
if(!function_exists('xyz_ips_plugin_get_version')) |
| 6 |
{ |
| 7 |
function xyz_ips_plugin_get_version() |
| 8 |
{ |
| 9 |
if ( ! function_exists( 'get_plugins' ) ) |
| 10 |
require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 11 |
$plugin_folder = get_plugins( '/' . plugin_basename( dirname( XYZ_INSERT_PHP_PLUGIN_FILE ) ) ); |
| 12 |
return $plugin_folder['insert-php-code-snippet.php']['Version']; |
| 13 |
} |
| 14 |
} |
| 15 |
|
| 16 |
if(!function_exists('xyz_trim_deep')) |
| 17 |
{ |
| 18 |
|
| 19 |
function xyz_trim_deep($value) { |
| 20 |
if ( is_array($value) ) { |
| 21 |
$value = array_map('xyz_trim_deep', $value); |
| 22 |
} elseif ( is_object($value) ) { |
| 23 |
$vars = get_object_vars( $value ); |
| 24 |
foreach ($vars as $key=>$data) { |
| 25 |
$value->{$key} = xyz_trim_deep( $data ); |
| 26 |
} |
| 27 |
} else { |
| 28 |
$value = trim($value); |
| 29 |
} |
| 30 |
|
| 31 |
return $value; |
| 32 |
} |
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
if(!function_exists('xyz_ips_links')){ |
| 38 |
function xyz_ips_links($links, $file) { |
| 39 |
$base = plugin_basename(XYZ_INSERT_PHP_PLUGIN_FILE); |
| 40 |
if ($file == $base) { |
| 41 |
|
| 42 |
$links[] = '<a href="https://xyzscripts.com/support/" class="xyz_support" title="Support"></a>'; |
| 43 |
$links[] = '<a href="https://twitter.com/xyzscripts" class="xyz_twitt" title="Follow us on Twitter"></a>'; |
| 44 |
$links[] = '<a href="https://www.facebook.com/xyzscripts" class="xyz_fbook" title="Like us on Facebook"></a>'; |
| 45 |
$links[] = '<a href="https://plus.google.com/+Xyzscripts/" class="xyz_gplus" title="+1 us on Google+"></a>'; |
| 46 |
$links[] = '<a href="https://www.linkedin.com/company/xyzscripts" class="xyz_linkedin" title="Follow us on LinkedIn"></a>'; |
| 47 |
} |
| 48 |
return $links; |
| 49 |
} |
| 50 |
} |
| 51 |
add_filter( 'plugin_row_meta','xyz_ips_links',10,2); |
| 52 |
|
| 53 |
if(!function_exists('xyz_ips_page_exists_by_slug')) |
| 54 |
{ |
| 55 |
function xyz_ips_page_exists_by_slug( $post_slug ) { |
| 56 |
$args_posts = array( |
| 57 |
'post_type' => 'page', |
| 58 |
'post_status' => 'any', |
| 59 |
'name' => $post_slug, |
| 60 |
'posts_per_page' => 1, |
| 61 |
); |
| 62 |
$loop_posts = new WP_Query( $args_posts ); |
| 63 |
if ( ! $loop_posts->have_posts() ) { |
| 64 |
return false; |
| 65 |
} else { |
| 66 |
$loop_posts->the_post(); |
| 67 |
return $loop_posts->post->ID; |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
if(!function_exists('xyz_ips_get_link_by_slug')) |
| 72 |
{ |
| 73 |
|
| 74 |
function xyz_ips_get_link_by_slug($slug, $type = 'page'){ |
| 75 |
$post = get_page_by_path($slug, OBJECT, $type); |
| 76 |
return get_permalink($post->ID); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
function xyz_ips_preview_page( $content ) { |
| 81 |
if ( strcmp( 'xyz-ics-preview-page', get_post_field( 'post_name' ) ) === 0 ) { |
| 82 |
|
| 83 |
$xyz_ips_snippetId=""; |
| 84 |
if(isset($_GET['snippetId'])) |
| 85 |
$xyz_ips_snippetId=intval($_GET['snippetId']); |
| 86 |
|
| 87 |
if($xyz_ips_snippetId!="" && is_numeric($xyz_ips_snippetId)) |
| 88 |
{ |
| 89 |
global $wpdb; |
| 90 |
|
| 91 |
$snippetDetails = $wpdb->get_results($wpdb->prepare( 'SELECT * FROM '.$wpdb->prefix.'xyz_ips_short_code WHERE id=%d LIMIT 0,1',$xyz_ips_snippetId )) ; |
| 92 |
if(!empty($snippetDetails)) { |
| 93 |
$snippetDetails = $snippetDetails[0]; |
| 94 |
|
| 95 |
$content = do_shortcode( '[xyz-ips snippet="'.esc_html($snippetDetails->title).'"]' ); |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
return $content; |
| 101 |
} |
| 102 |
|
| 103 |
add_filter( 'the_content', 'xyz_ips_preview_page' ); |
| 104 |
|
| 105 |
?> |
| 106 |
|