php 更新vc_icon并将您自己的内容添加到列表中

更新vc_icon并将您自己的内容添加到列表中

functions.php
// 1- update map for vc_icons

add_action( 'vc_after_init', 'hubble_vc_icon_settings' );
function hubble_vc_icon_settings() {
    
    if ( ! WPBMap::exists('vc_icon') )
        return false;

    $vc_icon_map = WPBMap::getShortCode('vc_icon');
    //$params = $vc_icon_map['params'];
    $vc_icon_map['params'][0]['value'] = array(
                    __( 'Hubble Icons', 'hubble' ) => 'hubbleicons',
                    __( 'Font Awesome', 'hubble' ) => 'fontawesome',
                    __( 'Open Iconic', 'hubble' ) => 'openiconic',
                    __( 'Typicons', 'hubble' ) => 'typicons',
                    __( 'Entypo', 'hubble' ) => 'entypo',
                    __( 'Linecons', 'hubble' ) => 'linecons',
                    __( 'Mono Social', 'hubble' ) => 'monosocial',
                    __( 'Material', 'hubble' ) => 'material',
                );
    

    $insert_icon = array(
        array(
            'type' => 'iconpicker',
            'heading' => esc_html__( 'Icon', 'hubble' ),
            'param_name' => 'icon_hubbleicons',
            'value' => 'oli oli-heart', 
            'settings' => array(
                'emptyIcon' => false,
                'type' => 'hubbleicons',
                'iconsPerPage' => 4000,
            ),
            'dependency' => array(
                'element' => 'type',
                'value' => 'hubbleicons',
            ),
            'description' => esc_html__( 'Select icon from library.', 'hubble' ),
        )
    );
    array_splice( $vc_icon_map['params'], 1, 0, $insert_icon ); // splice in at position 3
    
    vc_map_update('vc_icon', 'params', $vc_icon_map['params']);
    
}

// 2- add your icon set
function hubble_iconpicker_type_hubbleicons($icons)
{
    $hubble_icons = array(
        array( 'oli oli-Orcid'=>'Orcid' ),
        array( 'oli oli-GoogleScholar'=>'GoogleScholar' ),
        array( 'oli oli-GoogleScholar2'=>'GoogleScholar2' ),
        array( 'oli oli-ResearchGate'=>'ResearchGate' ),
        array( 'oli oli-ResearchGate2'=>'ResearchGate2' ),
        array( 'oli oli-Mendeley'=>'Mendeley' )
        // ...
    );

    return array_merge( $icons, $hubble_icons );
}
add_filter( 'vc_iconpicker-type-hubbleicons', 'hubble_iconpicker_type_hubbleicons' );

// 3- enqueue your icon set ad admin
function hubble_enqueue_kelpericons_css($font){
    wp_register_style( 'kelpericons', HUBBLE_CSS . '/ol-icons.css',array(),HUBBLE_THEME_VERSION);
    wp_enqueue_style( 'kelpericons' );
}
add_action('admin_enqueue_scripts', 'hubble_enqueue_kelpericons_css');

php charge.php

index.php
<?php require_once('./config.php'); ?>

<form action="charge.php" method="post">
  <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
          data-key="<?php echo $stripe['publishable_key']; ?>"
          data-amount="5000" data-description="One year's subscription"></script>
</form>
config.php
<?php
require_once('vendor/autoload.php');

$stripe = array(
  secret_key      => "sk_test_332kjf2jkewkw",
  publishable_key => "pk_test_n32ikj323k2kf"
);

\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>

charge.php
<?php
  require_once('./config.php');

  $token  = $_POST['stripeToken']; // retrieve stripeToken POST parameter to charge the card

  $customer = \Stripe\Customer::create(array(
      'email' => $_POST['stripeEmail'],
      'card'  => $token
  ));

  $charge = \Stripe\Charge::create(array(
      'customer' => $customer->id,
      'amount'   => 5000,
      'currency' => 'usd'
  ));

  echo '<h1>Successfully charged $50!</h1>';
?>

php 【WordPress的】的Jetpackを有效化しているサイトをクローンしてテスト环境を作るときに的wp-config.php文件に记述すべき设定

【WordPress的】的Jetpackを有效化しているサイトをクローンしてテスト环境を作るときに的wp-config.php文件に记述すべき设定

gistfile.php
<?php

define( 'JETPACK_STAGING_MODE', true );

php 使用CDATA围绕节点值或使用转义HTML构建XML文件

使用CDATA围绕节点值或使用转义HTML构建XML文件

build_xml.php
<?php
$counter = 0;

$sql = "SELECT * FROM jobs ORDER BY id ASC";
$featuredjobs = mysqli_query ($cn, $sql);

$xml = new DomDocument('1.0', 'utf-8');
$xml->formatOutput = true;

$dataset = $xml->createElement("data-set");
$xml->appendChild($dataset);

while($row = mysqli_fetch_array($featuredjobs, MYSQLI_ASSOC)) {

	// create record node
	$record = $xml->createElement("record", "");
	$dataset->appendChild($record);

		// create record > title node
		$title = $xml->createElement("title", $row['title']);
		$record->appendChild($title);

		// create record > city node
		$city = $xml->createElement("city", $row['city']);
		$record->appendChild($city);

		// create record > state node
		$state = $xml->createElement("state", $row['state']);
		$record->appendChild($state);

		// create record > body node
		// $body = $xml->createElement("body");
		// $body = $xml->createCDATASection($row['body']);
		// $record->appendChild($body);
		
		// create record > body node
		// $body = $record->appendChild($xml->createElement('body'));
		// $body->appendChild($xml->createCDATASection($row['body']));

		$body = $xml->createElement("body", htmlspecialchars($row['body']));
		$record->appendChild($body);

		$counter++;
}

$xml->save("jobs.xml");

mysqli_free_result($featuredjobs);
mysqli_close($cn);
?>

php 具有缩略图大小的ACF图像阵列简单输出

具有缩略图大小的ACF图像阵列简单输出

acf-image-array-output.php
<?php
				// first, get the image object returned by ACF
				$banner_object = get_field('banner_background_image');
				// and the image size you want to return
				$banner_size = 'banner';
				// now, we'll exctract the image URL from $image_object
				$banner_url = $banner_object['sizes'][$banner_size];
				?>
				
				<!--then output the url of the thumb size as defined-->
				<img src="<?php echo $banner_url; ?>" />

php Access-Control-Allow-Origin Snipet

Access-Control-Allow-Origin Snipet

Access-Control-Allow-Origin.php
<?php

// tells the CDN that the content 'Vary' depending on 'Origin' request header
header('Vary: Origin', true);

// allowed origins
$allowed_http_origins = array(
	'http://example.com',
	'http://www.example.com',
	'http://127.0.0.1',
	'http://localhost',
);

// get Origin sendend by the client if any
$http_origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : FALSE;

// check if the Origin is a allowed one
if ($http_origin !== FALSE && in_array($http_origin, $allowed_http_origins))
{
	// set the Access-Control-Allow-Origin to allow the requested origin
	header('Access-Control-Allow-Origin: ' . $http_origin, true);
}

php 获取远程数据Wordpress

获取远程数据Wordpress

wp-remoto.php
<?php
header("Content-type: application/json; charset=utf-8");

$http_origin            = $_SERVER['HTTP_ORIGIN'];
$allowed_http_origins   = array(
    "http://site1.com.br",
    "http://site2.com.br",
    "http://site3.com.br"
);
if (in_array($http_origin, $allowed_http_origins)){
    header("Access-Control-Allow-Origin: " . $http_origin);
}

//ADD IN ROOT PATH WORDPRESS
define( 'WP_USE_THEMES', false );
require( dirname(__FILE__) . '/wp-load.php' );

$args = array(
    'post_status'       => 'publish',
    'post_type'         => 'post',
    'caller_get_posts'  => 1, //IGNORAR POSTS FIXO
    'posts_per_page'    => 6,
    'order'             => 'DESC',
    'orderby'           => 'date'
);

$query = new WP_Query( $args );
$posts = $query->get_posts();

$output = array();
foreach( $posts as $post ) {

    $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium' );
    $url   = $thumb['0'];
    $category = get_the_category( $post->ID );
    $output[] = array(
        'ti_titulo' => $post->post_title,
        'ti_link'   => get_the_permalink(),
        'ti_imagem' => $url,
        'ti_autor'  => get_the_author_meta( 'display_name', $post->post_author ),
        'ti_data'   => $post->post_date,
        'ti_categoria' => $category[0]->slug
    );
}
wp_reset_postdata();
echo json_encode( $output );

php 逗号分隔符ForEach循环除了最后

逗号分隔符ForEach循环除了最后

foreach-separator.php
<?php
  $arr = array(1,2,3,4,5,6,7);
  $copy = $arr;
  foreach ($arr as $val) {
      echo $val;
      if (next($copy )) {
          echo ','; // Add comma for all elements instead of last
      }
  }
?>

php 在Wordpress帖子编辑器页面添加第二个TinyMCE编辑器。第二个编辑器看起来和功能完全像原始的编辑器一样

在Wordpress帖子编辑器页面添加第二个TinyMCE编辑器。 #php #wordpress

WP_secondary_editor.php
/* Second Post Editor TinyMCE Editor */
class SubContentEditor {

	public $meta_key = 'subcontent';
	public $meta_label = 'Right Side'; // Headline above editor
	public $post_type = array( 'page' ); // The post type in which the editor should display
	public $wpautop = true; // Automatically create paragraphs?

	function __construct() {
		add_action( 'edit_form_after_editor', array( &$this, 'edit_form_after_editor' ) );
		add_action( 'save_post', array( &$this, 'save_post' ) );
		add_action( 'init', array( &$this, 'init' ) );
	}

	public function init() {
		$this->meta_key = apply_filters( 'roman-sce-meta_key', $this->meta_key );
		$this->post_type = apply_filters( 'roman-sce-post_type', $this->post_type );
		$this->meta_label = apply_filters( 'roman-sce-meta_label', $this->meta_label );
		$this->wpautop = apply_filters( 'roman-sce-wpautop', $this->wpautop );
	}

	public function edit_form_after_editor() {
		if ( !is_admin() ) { return; }

		if ( in_array( get_post_type( $GLOBALS['post'] ), $this->post_type ) ) { return; }

		$value = $this->get_the_subcontent();

		$sc_arg = array(
			'textarea_rows' => apply_filters( 'roman-sce-row', 10 ),
			'wpautop' => $this->wpautop,
			'media_buttons' => apply_filters( 'roman-sce-media_buttons', true ),
			'tinymce' => apply_filters( 'roman-sce-tinymce', true ),
		);

		echo '<h3 class="subcontentLabel" style="margin-top:15px;">' . $this->meta_label . '</h3>';
		wp_editor( $value, 'subcontent', $sc_arg );

	}

	public function save_post( $post_id ) {
		if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
			return $post_id;
		}
		if ( ! current_user_can( 'edit_post', $post_id ) ) {
			return $post_id;
		}

		if ( isset ( $_POST[ $this->meta_key ] ) ) {
			return update_post_meta( $post_id, $this->meta_key, $_POST[ $this->meta_key ] );
		}
		delete_post_meta( $post_id, $this->meta_key );

		return $post_id;
	}

	public function get_the_subcontent() {
		global $post;
		$subcontent = do_shortcode(get_post_meta( $post->ID, $this->meta_key, true ));
		if ( $this->wpautop == true ) {
			return wpautop( $subcontent );
		} else {
			return $subcontent;
		}
	}

}
$romanSCE = new SubContentEditor();

function get_the_subcontent() {
	global $romanSCE;
	return $romanSCE->get_the_subcontent();
}

/** 
  * use get_the_subcontent() where you want the content of the
  * second editor to display, just like the_content
  */
function the_subcontent() {
	echo get_the_subcontent();
}

php 示例API具有特定列和分页Laravel没有Dingo

示例API具有特定列和分页Laravel没有Dingo

ApplicantController.php
<?php

class ApplicantController extends Controller
{
    public function index(Request $request)
    {
        $status = array_map('intval',explode(',',$request->input('status')));

        $sortBy = $request->has('sort') ? $request->input('sort') : 'id';
        $limit = $request->has('limit') ? $request->input('limit') : self::$paginationLimit;
        $orderBy = $request->has('order') ? $request->input('order') : 'desc';
        $filterBy = $request->has('filter_by') ? $request->input('filter_by') : 'assign_to';
        $assignedUser = $request->has('owner') ? [$request->input('owner')] : User::whereNotIn('role_id',[2])->get()->pluck('user_id')->toArray();
        $shouldFilter = $request->has('activate_filter') ? $request->input('activate_filter') : 0;
        $filterStatus = $request->has('status') ? $status : ApplicationStatus::all()->pluck('id')->toArray();

        $query = $this->applicant->whereHas('application', function($q) use ($filterStatus) {
            //$submitted_status = ApplicationStatus::all()->pluck('id')->toArray();

            $q->whereIn('application_status_id',$filterStatus);

        })->with('application','application.previousApplicationStatus','application.applicationStatus')

            ->with(['assigner' => function($q){

            $q->select('user_id','email','role_id');

        }])->with(['parent' => function($query){

            $query->select('id','first_name','middle_name','last_name');
        }])->with( ['application.attachment' => function ($q) {
            $q->where('code', '=', 'minute_meeting');
        }])->with( ['travel_document' => function ($q) {
            $q->select('applicant_id','travel_document_number');
        }])



            ->newQuery();

        if($shouldFilter == 1 ) {
            $query->whereIn($filterBy,$assignedUser);
        }

        //search by textfield (first_name/last_name/email/application_no/travel_document_number)

        if (!empty($request->filter_keyword)) {

            $filter_keyword = $request->filter_keyword;
            
            $query->where(function ($query) use ($filter_keyword) {
                            $query->orWhere('first_name', 'like' , '%'.$filter_keyword.'%')
                                ->orWhere('last_name', 'like' , '%'.$filter_keyword.'%')
                                ->orWhere('email', $filter_keyword)
                                ->orWhereHas('application', function ($query) use ($filter_keyword) {
                                    $query->where('application_no', $filter_keyword);
                                })
                                ->orWhereHas('travel_document', function ($query) use ($filter_keyword) {
                                    $query->where('travel_document_number', $filter_keyword);
                                });
                        });
        
        }

        $query->orderBy($sortBy,$orderBy);

        $applicant = $query->paginate($limit);
        $applicant->appends($request->all());

        return response()->json(compact('applicant'));
    } 
  
  
}